Htaccess and 301 redirects


I have some URLs indexed by Google, which are now old and no longer go to the page indexed (were search pages).

I’d like these URLs redirected to my homepage.

The URLs are in the format of:

What I’m looking for really, is for anything that has ‘catalogsearch’ in the URL to redirect to the homepage, i.e.

Is this possible using a htaccess file?


I dont’t think that will work, since the URLs have query strings and RewriteRule’s wont work. I think I need a RewriteCond, but I’m not sure how I’d match any URLs with ‘catalogsearch in them and redirect to the root domain…’

Try this:

Options +FollowSymlinks -Indexes

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteRule ^oldpage$ [R=301,L]

If you need to base on query string then use:

RewriteCond %{QUERY_STRING} ^id=8875&cat=234&sec=346$
RewriteRule ^index\\.php$ [R=301,L]

Is there not an easier way of just matching the word ‘catalogsearch’ in the URL ( and redirecting? Some URLs might differ in terms of the query string parameters, so I’d just like to match anything with catalogsearch, which is always first in the URL params.

I do not understand where is catalogsearch in URL or in query?

If you have the addresses like
then just use like I have written before, because query does not matter:

RewriteRule ^catalogsearch\\.php$ [R=301,L]


RewriteRule ^catalogsearch.\\.php$ [R=301,L]


If you read my initial post, I mentioned the URL:

I need to be able to detect the ‘catalogsearch’ string in the URL, if I find it, redirect to - unfortunately, your example did not do this.

Adam, if you only want to check if a URL starts with something, don’t use the $ at the end :wink:

sipher, try this

RewriteEngine On

RewriteRule ^catalogsearch [L,R=301]



RewriteRule ^catalogsearch/.*$ [R=301,L]

Ok, but that just removes the


I still have the query string params…

RewriteRule ^catalogsearch/.*$ [R=301,L]

Just add question mark at the end.

Brilliant!!! That’s what I was missing. Thank you!


Redirect 301 catalogsearch/

I believe that will also kill the query string but not sure about this factor.


NEVER leave <IfModule> tests in place on a production server as they will KILL the server’s performance.

As the other responder pointed out, the query string is unaffected by a mod_rewrite directive (which does not alter the query string). Also, the query string can be removed by adding a ? after the redirection - but, when mod_alias’s Redirect is the proper Apache tool to use and it doesn’t forward the query string, why bother? I’m a real fan of the power of mod_rewrite but the most important thing to understand is when to use it and when not to use it. Here, it’s better to use the proper tool: mod_alias’s Redirect.