views:

18

answers:

1

Hi Guys,

I have several URLs that I want to redirect to the same place, however these are dynamic URLs.

The structure is something like this:

http://www.mysite.com/declaration/list?[query_string]

What I think would be ideal for this situation is to use some regex in my .htaccess file to redirect all these links to the sites home page.

I was wondering if someone could help me with the regex for this situation. So far, I have this, but it doesn't work:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^/declaration/list$ http://www.mysite.com/$ [R=301,L]

My regex is weak to say the least, something I want to, and am trying to learn.

Thanks in advance. Tom

+3  A: 

Since you’re using mod_rewrite in a .htaccess file, you need to remove the contextual path prefix from the patterns. So try this:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^declaration/list$ http://www.example.com/ [R=301,L]

And since .* will match any string, your RewriteCond directive has no additional use:

RewriteRule ^declaration/list$ http://www.example.com/ [R=301,L]

And if you don’t want the query to be automatically appended to the new URL, specify an empty query in your substitution:

RewriteRule ^declaration/list$ http://www.example.com/? [R=301,L]
Gumbo
this doesn't seem to work either. It may be worth mentioning that this is a wordpress site, so there is some wordpress .htaccess configuration involved too. Thanks for your response.
Tisch
@Tisch: Put your rule above the ones of Wordpress.
Gumbo
you the man man. :D
Tisch