So I donât normally write web dev stuff on HackerNoon because Iâm not a dev at all and donât want to embarrass myself. However, I was faced with a big issue on my anime and Japan blog recently that Iâm sure others have faced as well; I disabled AMP (for various reasons), so my AMP pages were 404ing, and I needed to redirect them to their non-AMP counterparts.
In this article, Iâll show you a quick 1-minute fix to redirect ALL your AMP pages in bulk to their non-AMP counterparts. I should note that there are various ways to do this outlined in this article: Nginx, Apache, and Cloudflare. However, I was taught this fix is way quicker and doesnât require editing files.
Table of Contents:
-
Why my AMP pages were 404ing
-
How to redirect AMP pages one by one
- Plugin
-
How to redirect AMP pages in bulk
- Expressions
Why Are My AMP Pages 404ing?
I think the AMP plugin developer needs to fix this.
For various reasons, I decided to disable AMP on my WordPress site. The AMP plugin auto-generates all your pages into their AMP forms, and Google usually prefers those pages for mobile and indexes the AMP URL.
The issue with that is when you disable the AMP plugin, all the AMP URLs will still be indexed on Google, and when people click them, they will be served a 404 error page or an OOPS that canât be found page.
AMP should auto-redirect all AMP URLs to their regular URL counterparts if the user disables the plugin.
But alas, the plugin doesnât do that, and weâre left with dozens or hundreds of URLs that no longer exist, and we have to redirect them.
How to redirect AMP pages one by one
So the plugin youâll need to download (if you donât already have it) is Redirection by John Godley. And believe me, it is aâŚgodly plugin đ
The Redirection Plugin
In this section, Iâll explain how to redirect single AMP URLs one by one if, for whatever reason, you donât want to redirect them all.
Once youâve installed the plugin, you should be able to access it on your WP dashboard under tools â redirection:
It should look like this:
In the Source URL, you put the AMP url slug (no need to add your domain) : /my-post-2/amp/
And the closed bracket / at the end is necessary.
In the Target URL you need to put your redirect which would be the exact same minus /amp/
and thus should just be something like /my-post-2/
.
Click âadd redirectâ and you should be done! Be sure to check the AMP url to see if its redirecting properly.
How to redirect AMP pages in bulk
If you want to redirect ALL your AMP pages in one go, we can use the same plugin as above and itâll take literally 1 minute or so.
Step 1. Navigate to the Redirection plugin
Step 2. Set Regex option
Step 3. Input the proper URL expressions
Step 4. Add redirect
Navigate to the Redirection plugin using the same steps as in the above section.
This time, click on URL options/Regex.
Select Regex.
This time, in the Source URL, you need to add this expression ^/(.*?)/amp/$
In the Target URL input, this expression /$1/
Click âadd redirectâ, and you should be done!
Check to see if this worked by adding /amp/ to any of your articles and seeing if it auto-redirects. You can do the same on your mobile phone.
If this doesnât work, your WP site might be using a different URL structure. You can see a more in-depth list of expressions to use here.
Final Thoughts
Thatâs it! I hope this worked for you because it was super frustrating for me, and I didnât feel like learning where my htc access file was and then learning how to edit it.
Luckily, this plugin makes it easy and doesnât require any in-depth development knowledge.
If that doesnât work for you, or you know a better way to do this, please comment below! Iâm not an expert, but Iâd be happy to help you if I can.