.htaccess redirect/rewrite help needed

Tag: .htaccess Author: firefox191 Date: 2009-08-31

I am writing htacess redirect rule but it is not working properly I have tried many solutions but simply it is not working.

What I want to do is to I have url http://example.com/cms/index.php?page=filename I want this url to be executed and show appropriate page but in browser it should show example.com/cms. And what is important is I only want to right this rule for this page only and it should not effect to other pages.

Thank you.

What was your attempt?

Best Answer

RewriteRule ^([^/]+)/$ /cms/index.php?filename=$1 [L,QSA]

The L at the end says it is the last rule (stop processing) and QSA means 'Query String Append', so if someone puts other parameters after it, such as:


The GET value for order will be passed also - without it it'll just quietly drop it.


+1: Your answer was a more thorough solution :-)

Other Answer1

Something like this ought to work:

RewriteEngine on
RewriteRule ^http://example.com/cms$ http://example.com/cms/index.php?page=filename

...should work.

Have a look at a tutorial with some examples if you're interested in seeing what else you can do.