Few days ago I disabled AMP support on my site.
To disable AMP support, I took the following steps.That is all I had to do, and 24 hours later AMP link to my site was gone from Google Search Results.
The only issue I noticed is that old AMP links were now returning a 404 – Page Not Found message.
For example:
https://www.alexkras.com/my-history-with-web-development-or-javascript-fatigue/amp would return 404 since there was no longer a /amp version of the link.
Redirect All 404s to HomepageTo remedy this issue, I've downloaded the All 404 Redirect to Homepage
As the name of plugin suggests, it will redirect all 404 to the home page. I already have a list of all post on my homepage rendered, via Clean My Archives plugin, so it was a decent solution in and of itself.
Redirect All AMP links to non AMP versionI wanted to take it one step further, though, so I modified the plugin to re-write AMP links to non amp version.
The steps to do so were as follows:
if (strpos($link, "/amp") !== false) { header ('HTTP/1.1 301 Moved Permanently'); header ("Location: " . str_replace('/amp', '', $link)); exit(); }
if (strpos($link, "/amp") !== false) {
header ('HTTP/1.1 301 Moved Permanently');
header ("Location: " . str_replace('/amp', '', $link));
exit();
}
It should look as the following image:
Finally, test it by navigating to an /amp version of any page on your site (after you've disabled AMP) to confirm that the redirect worked.
I am planning to write a proper WordPress plugin and publish it on Github, if there is interest. Please follow me on Twitter if you would like to hear more or DM me if you'd like to participate.
For now I wanted to share this quick hack as a stop-gap solution, until the proper plugin can be developed.
Source: How to Disable AMP on WordPress
No comments:
Post a Comment