Adding a redirection on an URL containing GET variables

On a normal URL you would just do

RewriteEngine on
RewriteBase /
RewriteRule ^old/url.html$ new/filename [R=301,L]

When you come to URL with GET variables, it doesn’t work directly. You need to catch the query string separately from the normal URL. To move old/url.php?id=2&var=760 to new/post-name, we can do it with a Rewrite condition like this:

RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^id=2\&var=760$
RewriteRule ^old/url.php$ new/post-name [R=301,L]

I don’t know if you need to escape the &, maybe not. I spent so much time before finding this that I didn’t test. Thanks a lot Carolyn Shelby for sharing this trick!!

Source: http://www.cshel.com/web-development/2009/06/mod_rewrite-rewritecond-query_string/

Advertisements
This entry was posted in IT stuff and tagged , . Bookmark the permalink.

One Response to Adding a redirection on an URL containing GET variables

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s