Hi, I want to do some url rewriting but i don’t really want to use mod_rewrite. I used to work for a company and i’m sure one of the dev’s did some rewtie work using a php script…so all requests went to cone page like site.com/categories.php?id=12 and then categories did some stuff and the resulting url ended up being something like site.com/sportswear…
any ideas how I could achieve this…i’m almost thinking I could have categories.php grab the $_GET, look up the db for the category name and retireve all info i need and then do some sort of rediect and utulise the info i got form the query somehow.
If you really don’t want to use mod-rewrite, then you can use the approach that IPB uses.
Links are constructed like so: http://yoursite.com/index.php?/Page/Product
Then in your code you take everything after ‘?’, split it by ‘/’ and run the relevant file.
Not the same, but very similar.
Sorry again…I was still trying to access the pages through .page.php?cat=prdouct and expecting it to change the url…when i go page/Product it works fine!!!
Thanks
hmm,
I kind of followed the article I posted above but it’s not working…The htaccess file is definitely being called as if i put garbage in there and any page in the directory it sits in gives me a 500 error…upon removing the garbage it’s all ok again- i’m pretty sure this means it’s being called…i’ve also chmod all the permissions to 777 just to make sure it’s being called.
so the format of my link is:
page.php?cat=People
and the rewrite stuff is:
RewriteEngine on
RewriteRule ^cat/([^/\.]+)/?$ page.php?cat=$1 [L]
is this correct?
I’m, kind of thinking it should be:
RewriteRule ^page/([^/\.]+)/?$ page.php?cat=$1 [L]
to match the page in the page.php part of the url but that doesn’t work either.
I’m not sure what the rewrite rule tried to match…anything after the ? or just anything in the complete url ?
HI, thanks for the reply,
So once the request gets to index.php how do it get the url looking like i want?
Are there ways to do this without mod_rewrite? Yes, and no. In reality the simple thing to do is to use mod_rewrite. As for using PHP alone, no that is not possible. The server must send the request to the PHP file in same way.
You will need at least one mod_rewrite rule to send the request to PHP.
RewriteEngine On
# Point all non-existing files/folders to index.php
# Then have PHP parse $_SERVER['REQUEST_URI']
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .? index.php [QSA,L]