.htaccess RewriteRule help

Associate
Joined
18 Sep 2003
Posts
2,366
I'm struggling a bit with apaches rewriterule

have 3 files in a folder


/review/apple.html
/review/orange.html
/review/pear.html


I want my links from my homepage to be tidy without the file extension, ie links are:
/review/apple
/review/orange
/review/pear etc


how I use the rule so /review/apple.html points to --> /review/apple and so on?

I can do this with a forward but I dont want the file extension popping up in the address bar!

thanks
 
A quick and simple (i think), although maybe not the best way to do it is:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^contact-us$ /contact-us/ [R]
RewriteRule ^contact-us/$ /contact.php

</IfModule>

First one redirects from /contact-us to /contact-us/
Second one in the background loads /contact.php when /contact-us/ is called.

Now with a bit of regex fiddling it could be modified easily to be more versatile.
 
/Hijack

localhost/27thblog/posts.php?post_id=1/lorem-ipsum2

to become

localhost/27thblog/post/1/lorem-ipsum2

Been killing me all day.

thank you :)

If I've understood you right, something like should work:

RewriteRule ^posts.php?post_id=1/(.*) /27thblog/post/1/$1 [R=302]
 
Back
Top Bottom