htaccess: How to redirect index.php?search= to the base url
how can i redirect index.php?search= to the base url? I tried it with this 开发者_StackOverflow中文版code:
redirectMatch 301 ^/index.php?search=(.*) http://www.yoursite.com/
but then the page loops the code if i enter the site domain..
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.
Try:
RedirectMatch permanent ^/index.php?search=(.*)$ http://www.yoursite.com/
精彩评论