小编Dan*_*Dan的帖子

终极移动.htaccess重定向

我已经使用下面的.htaccess代码为移动/桌面重定向提供了一个不错的工作解决方案,但是如果有人可以提供帮助,还有一些可以真正实现最终的增强功能.

目录设置:

  • 桌面网站:website.com
  • 移动网站:m.website.com

Cookie启用链接:

  • 从桌面站点移动到移动站点,设置cookie以保持在移动设备上:http://m.website.com?m = 1
  • 从移动站点到桌面站点,设置cookie以保持在桌面上:http://www.website.com?m = 0

当前.htaccess文件:

RewriteEngine on

# Check if this is the desktop to mobile query string
RewriteCond %{QUERY_STRING} (^|&)m=1(&|$)

# Set a cookie, and skip the next 2 rules 
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=2]

# Check if this is the mobile to desktop query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)

# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]

# Check if we're not already …
Run Code Online (Sandbox Code Playgroud)

.htaccess mobile redirect

6
推荐指数
1
解决办法
3278
查看次数

标签 统计

.htaccess ×1

mobile ×1

redirect ×1