views:

17

answers:

2

I've got to redirect a URL that has a question mark in it, and I just can't figure out the proper .htaccess code to make it happen.

Example: redirect 301 /home.php?cat=16 http://www.example.com/furniture.html

I believe I need to do a rewrite condition, but I'm no htaccess expert.

+1  A: 

With the Redirect directive from mod_alias you can only examine the URI path and not the query (applies to all directives of mod_alias). If you want to examine the URI query you need to use mod_rewrite:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=16$
RewriteRule ^home\.php$ http://www.example.com/furniture.html? [L,R=301]

The empty query in the replacement will prevent that the original query is being appended to the new URI.

Gumbo
That worked. Thanks Gumbo!
Joe Fletcher
A: 

From the apache2 mod_rewrite docs:

What is matched?

The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string. If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

Marian