简体   繁体   中英

Htaccess does not redirect mobile users to domain.com/m

My page can be accessed through domain.com or www.domain.com
I am trying to have a redirect for users on mobile devices to the domain.com/m or *www.domain.com/m*

However I am having difficulties to do this correctly. I have put this in my .htaccess on index.php of domain.com

How to do this correctly?

RewriteCond %{REQUEST_URI} !^/http://www.domain.com/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

Just find that fabulous Website. You got so many possibilities to make a mobile-redirect and they are updated frequently.

http://detectmobilebrowsers.com/

Hope it help you !

Try this:

RewriteCond %{HTTP_USER_AGENT} "android" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "ipad" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "iphone" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "ipod" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "iemobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "opera mobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palmos" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "webos" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile" [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

I did it in this is way:

RewriteCond %{HTTP_USER_AGENT}  (iphone|ipod|android|symbian|windows\ phone|blackberry|iemobile|opera\ mobile|palmos|webos|googlebot-mobile)   [NC]
RewriteRule ^(.*)$ /m/ [L,R=302]

and for me, it is working like a charm.

The .htaccess file in HTML5 Mobile Boilerplate actually handles this redirection nicely.

You should take a look either you are working with mobile or not or if you just want to redirect certain UA clients.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM