Forum Moderators: phranque
http://www.example.com/start.php?state=NY
I need to redirect with 301 all these access to
http://www.example.com/database.php?state=NY
I tried to use this rule, but it not works:
RewriteRule ^start.php?state=([a-zA-Z]{2})$ /database.php?state=$1 [R=301,L]
Anyone knows what is wrong?
[edited by: jdMorgan at 3:39 pm (utc) on July 20, 2007]
[edit reason] example.com [/edit]
RewriteCond %{QUERY_STRING} ^state=[a-z]{2}$ [NC]
RewriteRule ^start\.php$ /database.php [R=301,L]
Jim
The RewriteRule directive ignores QUERY_STRING arguments by default. To remedy this, use the Query String Append Flag: QSA. It causes the query string to be retained as it is and appended to the end of the resulting request.
Try this per-server:
RewriteEngine On
# Only redirect if state=NY
RewriteCond %{QUERY_STRING} state=NY
RewriteRule ^/start\.php /database.php [QSA,L,R=301]
And this if you are using a .htacess-file:
RewriteEngine On
# Only redirect if state=NY
RewriteCond %{QUERY_STRING} state=NY
RewriteRule ^start\.php /database.php [QSA,L,R=301]
Change the pattern in the RewriteCond to state if you just want to make sure that state is in the query string but don't care about its value.
This should solve your problem (I hope =))...
J
There is absolutely no need to use [QSA] in this application. [QSA] is only needed if you wish to create new query string name/value pairs *and* append them to the pre-existing query string. If you do not have a pre-existing query string, you don't need it. If you don't create new name-value pairs in the rule, you don't need it.
If no new query parameters are created by the rule, then the existing query string is passed through mod_rewrite rules unchanged. That was the point of my previous post -- unnecessary complication.
Jim