.htaccesshttp-redirectamp-html

How to make a 301 redirect rule for old AMP pages?


My website was on an old AMP plugin which added /amp/ after every post/page URL.

So my home for example is: https://example.com and the "amp" one was https://example.com/amp/.

I wanted to know what rule can I put in the .htaccess file to make a redirect of all these /amp/ URLs to the "normal" page itself.

So for example: https://example.com/my-article-1/amp/ redirects to https://example.com/my-article-1/, https://example.com/my-article-2/ redirects to https://example.com/my-article-2/ and it does for every article/page.

I'm sure it's possible to do it without typing 1000 lines of 301 "easy" redirects in .htaccess!


Solution

  • Okay fellas,

    I found the solution, this is the Redirect Rule you need to put to say goodbye to /amp/:

    RewriteEngine On 
    RewriteCond %{REQUEST_URI} (.+)/amp(.*)$ 
    RewriteRule ^ %1/ [R=301,L]
    

    I hope it will be helpful