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

发布于 2024-12-09 21:17:05 字数 453 浏览 1 评论 0原文

我的页面可以通过 domain.comwww.domain.com
访问 我正在尝试将移动设备上的用户重定向到 domain.com/m 或 *www.domain.com/m*

但是,我很难正确执行此操作。我已将其放入domain.com 的index.php 的.htaccess 中

如何正确执行此操作?

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]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

久伴你 2024-12-16 21:17:05

试试这个:

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]

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]
无力看清 2024-12-16 21:17:05

只要找到那个神话般的网站即可。您有很多进行移动重定向的可能性,并且它们会经常更新。

http://detectmobilebrowsers.com/

希望对您有帮助!

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 !

思慕 2024-12-16 21:17:05

HTML5 Mobile Boilerplate 中的 .htaccess 文件实际上可以很好地处理此重定向。

您应该看看您是否正在使用移动设备,或者您是否只想重定向某些 UA 客户端。

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.

深爱不及久伴 2024-12-16 21:17:05

我是这样做的:

RewriteCond %{HTTP_USER_AGENT}  (iphone|ipod|android|symbian|windows\ phone|blackberry|iemobile|opera\ mobile|palmos|webos|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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文