tags:

views:

189

answers:

2

Hi, how can i redirect index.php?search= to the base url? I tried it with this code:

redirectMatch 301 ^/index.php?search=(.*) http://www.yoursite.com/

but then the page loops the code if i enter the site domain..

A: 

Try:

RedirectMatch permanent ^/index.php?search=(.*)$ http://www.yoursite.com/
clyfe
+1  A: 

mod_alias does only work on the URL path and not the query:

mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.

So try mod_rewrite instead:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^search=(.*)
RewriteRule ^/index\.php$ /? [L,R=301]

Or more general:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^([^&]*&+)*search=([^&]*)
RewriteRule ^/index\.php$ /? [L,R=301]

And if you want to use this rule the .htaccess file in your root directory, remove the leading slash from the patterns.

Gumbo