简体   繁体   English

Htaccess不会将移动用户重定向到domain.com/m

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

My page can be accessed through domain.com or www.domain.com 我的页面可以通过domain.comwww.domain.com访问
I am trying to have a redirect for users on mobile devices to the domain.com/m or *www.domain.com/m* 我正在尝试将移动设备上的用户重定向到domain.com/m或 * 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 我把它放在我的.htaccess上,在domain.com的index.php上

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/ 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. HTML5 Mobile Boilerplate中的.htaccess文件实际上很好地处理了这个重定向。

You should take a look either you are working with mobile or not or if you just want to redirect certain UA clients. 你应该看看你是否正在使用移动设备,或者你只想重定向某些UA客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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