views:

50

answers:

4

Hi All,

I'm trying to write what I thought was a pretty simple rule but either I'm missing something painfully obvious or it isn't such a simple rule. In fact two others have looked at it and no one can seem to tell what I'm doing wrong.

I just moved a site to a new platform and need to set up some 301 redirects from dynamic pages to specific urls.

products.asp?dept=15 needs to be redirected to http://www.example.com/products/collections/gourmet-side-dishes

All the examples I've found point me to something that looks like:

RewriteCond %{query_string} &dept=15
RewriteRule ^/products\.asp$ http://www.example.com/products/collections/gourmet-side-dishes/? [R=301,L]

However, this isn't working. Please help! I need to stop these pages from going to a 404.

Thanks in advance, Seth

A: 

Try a condition with a leading ampersand, which isn't present in your example URL, e.g.

RewriteCond %{query_string} dept=15
RewriteRule ^/products\.asp$ http://www.somedomain.com/products/collections/gourmet-side-dishes [R=301,L]
Paul Dixon
+1  A: 

You may need to take off the leading slash from your rewrite rule:

RewriteRule ^/products....
# becomes
RewriteRule ^products...
MrZebra
A: 

Turned out to be a combination of both tips, plus, I'm embarrassed to say, the ordering of my rules.

Final rule that worked for me is:

 RewriteCond %{query_string} dept=15 
 RewriteRule ^products\.asp$ http://www.somedomain.com/products/collections/gourmet-side-dishes? [R=301,L]
A: 

If you’re using a rule in a .htaccess file, the contextual per-directory path prefix is removed before testing and added back after applying a rule.

RewriteCond %{query_string} &dept=15
RewriteRule ^products\.asp$ http://www.example.com/products/collections/gourmet-side-dishes/? [R=301,L]

See the Per-directory Rewrites box in the description of the RewriteRule directive for further information.

Gumbo