Redirect AMP url to Non-AMP url in Nginx


AMP (Accelerated Mobile Pages) can be used for any site to load the content faster. We have shared a tutorial: How to Enable AMP in WordPress site. If you no longer wish to use the AMP functionality you can disable it. But there are many posts which have already been indexed by google search engine as AMP version will no longer work resulting a 404 error or “Page Not found” error. To solve the problem all you need is to redirect all those links to a non-amp version.

Add the following code inside virtual server block in nginx:-

location ~ /amp/$ {
rewrite ^(.*/)amp/$ $1 permanent;
}

The above will redirect all urls having /amp/ at the end to the non amp version of the url e.g.

https://wbxpress.net/display-post-modified-date-genesis-theme/amp/

will be redirected to

https://wbxpress.net/display-post-modified-date-genesis-theme/

That’s it. Now your site will be free from 404 error.

,

Leave a Reply

Your email address will not be published. Required fields are marked *