Waqas Ibrahim
Waqas Ibrahim

Reputation: 153

How can i redirect to AMP version of website on mobile?

Let's say i have one page website and it has two versions, one simple html file for desktops and one Google's AMP version for mobiles. How can i redirect to AMP version? Thanks

Upvotes: 2

Views: 2640

Answers (1)

Alphacoder
Alphacoder

Reputation: 299

Assuming your amp version is under /amp (http://example.com/amp), you can try redirecting your visitors in your .htaccess file like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/amp$ [NC]
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|googlebot\-mobile|iemobile|iphone|ipod|\#opera\ mobile|palmos|webos) [NC]
RewriteRule ^([a-zA-Z0-9-]+)([\/]*)$ https://example.com/$1/amp [L,R=302]

Upvotes: 2

Related Questions