移动cookie htaccess

发布于 2024-12-05 23:53:54 字数 479 浏览 0 评论 0原文

我有一个移动网站和一个桌面网站。我已经为移动用户设置了访问桌面网站时的自动重定向。但不幸的是,如果他们愿意的话,我也需要他们访问完整的网站。

我已在 .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 技术交流群。

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

发布评论

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

评论(2

恋竹姑娘 2024-12-12 23:53:54

为您的规则添加这种重写条件:

RewriteCond %{HTTP_COOKIE} mobile=yes

如果存在名为 mobile 且值为 yes 的 cookie(更准确地说,该模式),则允许执行规则将匹配任何mobile结尾的cookie名称(例如notmobile)以及yes开头的值(例如是的先生))。

如果您需要更精确(仅精确匹配)——您必须检查原始 cookie 的外观并相应地调整模式。但只要您有唯一的 cookie 名称和值,就不需要这样做。

Add this kind of rewrite condition for your rule:

RewriteCond %{HTTP_COOKIE} mobile=yes

This will allow rule to execute if cookie with the name mobile and value of yes is present (to be more precise, that pattern will match any cookie name that ends with mobile (e.g. notmobile) and value that starts with yes (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.

戏蝶舞 2024-12-12 23:53:54

标记——在您提供的参考链接中,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.

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