Search code examples
.htaccesshttp-redirect

How to forward to exact path using .htaccess Redirect 301?


I am having an issue in Google Search Console where I need to do a redirect on a page.

The URL is https://example.com/contact/?amp

Using .htaccess... It forwards as it should using the below code but I still get the ?amp . How do I get it to forward while losing the ?amp ?

Redirect 301 /contact.php/?amp https://example.com/contact.php

Any help would be appreciated! Thanks.

I tried using this:

Redirect 301 /contact.php/?amp https://example.com/contact.php

It forwards but includes the ?amp


Solution

  • The rewriting module offers much more flexibility:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^amp$
    RewriteRule ^/?contact\.php$ https://example.com/contact.php [R=301,END,QSD]
    

    The QSD flag is responsible for getting rid of the GET argument ("QueryStringDelete").