I want to direct all mobile traffic to the original access URL/amp
For example:
When the mobile phone accesses http://example.com, it will be directed to http://example.com/amp
When the mobile phone accesses http://example.com/123, it will be directed to http://example.com/123/amp
I need to do this through the apache server, so I use .htaccess for redirection
The following .htaccess settings can help me do it
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-]+)([\/]*)$ http://7abbd517.ngrok.io//amp [L,R=302]
http://example.com/123 leads to http://example.com/123/amp
But there is no way to help me achieve the redirection of the homepage
That is to say
「X」http ://example.com cannot go to http://example.com/amp
How should I rewrite it to achieve my original goal?
Since the plus sign after
[a-zA-Z0-9-]
means matching at least 1 element, so sincehttp://example.com
cannot match one element,+
is changed to*
that is But, in addition, there is no need to write the square brackets outside[/]
.