Category Archives: amp-html

Apache rule to minimize redirects

I have the following in apache host file to redirect from www to non-www version of the site:

RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

I also want to redirect anyone going to this url: =>

The problem is that if I add the following rule to my .htaccess, it results in an extra redirect:

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

What happens is that when anyone goes to it does two redirects:

First: => 301 to =>

Second: => 301 to =>

How can I modify the rules in the vhosts file to minimize this extra redirect?

Example urls of what should ideally happen: => => =>

That last one above is what I want to minimize a redirect for.


Here are both the vhosts (for port 80 and 443):

<VirtualHost *:80>
  DocumentRoot /var/www/html
  RewriteEngine on
  RewriteCond %{SERVER_NAME} [OR]
  RewriteCond %{SERVER_NAME}
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

<VirtualHost *:443>
  DocumentRoot /var/www/html
  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/
  SSLCertificateKeyFile /etc/letsencrypt/live/

How to redirect /amp URLs to the non AMP version?

Firstly, I would like to tell you guys that I have already searched the following threads for solutions, but they don't work.

.htaccess redirect /amp/ urls to nonamp version

How to redirect amp content to normal mode

Redirect from AMP URLs to Real URLs

I have added the rule: RewriteRule ^(.*)/amp$ $1 [R=301,L] in my .htaccess like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/amp$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

But it still doesn't take my amp links to their non-AMP original links. Please help me with this.

.htaccess rewriting URL to add a character to a URL

I'm doing this to fix an error with my AMP pages. I'm using the Automatic AMP plugin, and this plugin lets you access the AMP pages using 2 different methods


Using the AMP Page validator ( I see that all AMP pages using just /amp/ get multiple errors, while /?amp is validated correctly.

Unfortunately, Google is checking /amp/ for all my pages, hence I'm getting tons of errors.

What I'd like to know is how to use the .htaccess redirect rule to add the ? to the AMP queries so all /amp/ requests are redirected (with a 301) to /?amp/

I'd appreciate suggestions on this. Thank you