移动cookie htaccess
我有一个移动网站和一个桌面网站。我已经为移动用户设置了访问桌面网站时的自动重定向。但不幸的是,如果他们愿意的话,我也需要他们访问完整的网站。
我已在 .htaccess 文件中设置了 cookie,如何检查 cookie 是否已设置以便他们可以访问完整站点?还没有找到明确的答案。
代码:
#redirect
RewriteCond %{HTTP_HOST} !^m\.stage.sunjournal\.com$
RewriteCond %{HTTP_USER_AGENT} "android|iPhone|blackberry|ipad|iemobile|operamobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.stage.sunjournal.com/$1 [L,R=302,CO=mobile:yes:m.stage.sunjournal.com:0:/]
I have a mobile site and a desktop site. I have set up automatic redirection for mobile users if they access the desktop site. But unfortunately I need them to access the full site as well, if they prefer.
I have set up a cookie in the .htaccess file, how do i check to see if the cookie has been set so they can access the full site? Haven't found a clear answer.
Code:
#redirect
RewriteCond %{HTTP_HOST} !^m\.stage.sunjournal\.com$
RewriteCond %{HTTP_USER_AGENT} "android|iPhone|blackberry|ipad|iemobile|operamobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.stage.sunjournal.com/$1 [L,R=302,CO=mobile:yes:m.stage.sunjournal.com:0:/]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为您的规则添加这种重写条件:
如果存在名为
mobile
且值为yes
的 cookie(更准确地说,该模式),则允许执行规则将匹配任何以mobile
结尾的cookie名称(例如notmobile
)以及以yes开头
的值(例如
是的先生
))。如果您需要更精确(仅精确匹配)——您必须检查原始 cookie 的外观并相应地调整模式。但只要您有唯一的 cookie 名称和值,就不需要这样做。
Add this kind of rewrite condition for your rule:
This will allow rule to execute if cookie with the name
mobile
and value ofyes
is present (to be more precise, that pattern will match any cookie name that ends withmobile
(e.g.notmobile
) and value that starts withyes
(e.g.yesSir
)).If you need this to be more precise (exact match only) -- you have to check how raw cookie look like and adjust pattern accordingly. But as long as you have unique cookie name and value this will not be required.
标记——在您提供的参考链接中,cookie 设置为在用户退出会话后自行销毁。这是因为 cookie 的生命周期从未指定。有关此内容的更多信息,请访问 mod_write 官方文档 。
BDUB,我建议您查看马克提供的链接。我在设置新 cookie 时遇到问题,因为如果将 cookie 设置为 mobile=0,则不会设置我的 cookie mobile=1。我在我的 RewriteLogs 中看到了这一点。
Mark -- In the reference link you provided, the cookie is set to destroy itself after the user has exited their session. This is because the lifetime of the cookie was never specified. For more information about this, go to the official documentation for mod_write.
BDUB, I would suggest you check out that link that Mark provided. I'm running into issues setting the new cookie, because if a cookie is set for mobile=0, my cookie mobile=1 is not set. I have seen this in my RewriteLogs.