Hi everyone,
I couldnt find a forum on this specifically so I thought I would ask in the php forum. I am looking to re-write my urls from
http://www.example.com/page.php?id=119
to
http://www.example.com/page/119
If anyone can help me out with the code to accomplish this that would be great. I have been reading about it all day and I cant seem to get it straight.
I'm no .htaccess expert, but I've used a variation on the code below:
RewriteCond %{REQUEST_URI} ^/page/(\d+)$ RewriteRule ^/page/(\d+)$ /page.php?id=$1 [L]
I didn't test this code, so you may well have to modify it. You can also try searching on "htaccess search engine friendly URLs" to find alternatives.
Thanks for the reply but for some reason I still can not get it to work. I got it to say
http://www.example.com/page/?id=119
but that is not right and returns an error.
I'm not sure if you understood my message. The code I posted goes in the .htaccess file in the root directory of your website. Did you do that?
Yes that is how you do mod_rewrite. My redirects work fine but the url changes dont seem to work.
You could always try looking on the Apache website.
I have tried to decipher what they say but its as clear as mud.
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Probably you mixed rewrite and redirect Rewrite is when you enter "some.url/page/112" into browser address bar and the script is invoked as it was requested as "some.url/page.php?id=112" Redirect is when you enter "some.url/page.php?id=112" into browser address bar and the browser is redirected to "some.url/page/112" Which one do you need?
I'm not sure, but this should work. Check it out...
RewriteEngine On RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]
Or if its in a folder, it should be :
RewriteEngine On RewriteRule ^folder/page/([0-9]+)$ folder/page.php?id=$1 [L]