How to Seamlessly Redirect Accelerated Mobile Pages (AMP) to Non-AMP Pages

Redirecting AMP pages after disabling the functionality is crucial for avoiding site issues. This definitive guide covers implementing AMP to non-AMP redirects in Nginx, Apache, and Cloudflare.

Why Redirect AMP Pages? An Overview

Accelerated Mobile Pages (AMP) are stripped-down HTML pages designed by Google to load incredibly fast on phones. At one point, Google even required AMP for eligibility in Top Stories carousel.

However, maintaining separate AMP and non-AMP page versions is cumbersome. Recently Google removed the AMP requirement from Top Stories criteria.

As a result, many websites are disabling AMP support:

  • AMP adds development overhead
  • Hurts branding consistency
  • Causes duplicate content issues

Once AMP gets disabled though, you must properly redirect existing AMP URLs to avoid:

  • Landing visitors on 404 error pages
  • Google crawler errors saying "Referenced AMP URL is not an AMP page"

Configuring seamless 301 redirects from AMP to non-AMP pages in your infrastructure is crucial whenever disabling AMP functionality.

This guide covers step-by-step how to setup AMP to non-AMP redirects in:

  • Nginx web servers
  • Apache web servers
  • Cloudflare CDN

Follow along as we dive into configuration specifics for each platform:

Nginx: Redirect AMP to Non-AMP

Nginx is a high-performance open source web server used by over 13.5% of the top 1 million websites.

To configure AMP to non-AMP redirects:

  1. Edit your Nginx config file (nginx.conf)
  2. Add a rewrite rule to pass AMP URLs to non-AMP versions
  3. Restart Nginx

For example, open your server block config in /etc/nginx/nginx.conf and add:

rewrite ^/(.*)\/amp(.*)$ http://www.example.com/$1$2 permanent; 

This regular expression will match URLs containing /amp/ and rewrite without that portion:

  • ^/(.*)\/amp(.*)$ – Match AMP pattern
  • http://www.example.com/$1$2 – Non-AMP rewrite target
  • permanent – Returns 301 redirect

Then reload Nginx with sudo systemctl restart nginx and test a redirect by accessing an old AMP URL in your browser.

As noted by Nginx, the order of rules matters so placing this redirect before other rules is likely best.

Apache: .htaccess Redirects

For sites using the Apache web server, AMP to non-AMP redirects are handled in .htaccess. This file goes in your root or /public_html/.

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

The logic checks requests for /amp/, strips that portion out, and returns a 301 moved permanently redirect.

Cloudflare Redirects

Cloudflare operates a massive content delivery network and security service for sites. Luckily, build in Page Rules make redirecting AMP pages simple.

Create a new page rule:

URL Pattern: *example.com/*/amp/
Status: 301 Forwarding URL
Forwarding URL: https://example.com/$1

This will match AMP URLs and strip out /amp to form redirect target URL using the matched $1 placeholder.

Why 301 Permanent Redirects

You may notice that whether using Nginx, Apache, or Cloudflare we specifically implemented 301 permanent redirects from AMP to non-AMP pages.

The 301 code communicates to both visitors and search engine crawlers that the page has moved permanently to a new location.

Compare this to a 302 temporary redirect which may cause repeat crawler attempts to access AMP URLs that no longer exist. 301s clearly indicate the preference for the non-AMP URL.

Per Google‘s advice on redirects:

"When you change URLs of content, use server-side 301 HTTP redirects to forward search engines and visitors to the correct location of that content."

So in short, 301 redirects are crucial for clearly conveying that AMP pages definitively live at new non-AMP URLs now.

Testing AMP to Non-AMP Redirects

Verifying that redirects perform as expected is a must once configured.

Manually check by accessing a few old AMP links that may still be indexed or externally linked to. Append trailing slashes and remove them when testing too.

Additionally, tools like Redirect Checker validate status codes and final redirect destinations. I recommend testing with this tool to double check your redirects.

Lastly, keep an eye on crawl errors in Search Console related to invalid AMPs. Over time these should disappear as Googlebot picks up on the 301 redirects.

If you have a site map, also submit that to search engines again to expedite reindexing of the non-AMP destination pages.

Conclusion

Redirecting AMP to non-AMP after disabling the functionality prevents site issues like crawl errors and 404s. Yet implementing these redirects varies across different infrastructure.

In this guide, we covered how to seamlessly 301 redirect accelerated mobile pages to canonical non-AMP URLs in major platforms:

  • Nginx using rewrite rules
  • Apache via .htaccess tweaks
  • Cloudflare Page Rules for simplified setup

Properly redirecting AMPs takes a bit of initial effort. But once configured, redirects enable safely removing AMP without negative SEO or usability consequences.

Have you recently deactivated AMP pages? What approach did you take for redirecting AMP links? I welcome any questions in the comments!