Search code examples
apache.htaccesshttp-redirectmod-rewritelamp

301 Redirect URLs with special characters to homepage htaccess


I have about 90 URLs that look like this....

www.domain.com/index.php?page=about-us
www.domain.com/index.php?page=Testimonials
www.domain.com/index.php?page=contact-us-2
www.domain.com/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=184&cntnt01origid=68&cntnt01returnid=68

etc. etc.

I need to do a wildcard 301 redirect on any URL that contains /index.php? to the homepage. How do I go about this?

Thanks


Solution

  • You can use this rule as your very first rule in site root .htaccess:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+index\.php[?/\s] [NC]
    RewriteRule ^ /? [L,R=301]
    
    RewriteCond %{QUERY_STRING} ^(?:page|mact)= [NC]
    RewriteRule ^ /? [L,R=301]
    

    ? after / in target URI is for stripping off any query string that exists after index.php?