开发者

Mobile cookie htaccess

开发者 https://www.devze.com 2023-04-06 21:54 出处:网络
I have a mobile site and a d开发者_Python百科esktop 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

I have a mobile site and a d开发者_Python百科esktop 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:/]


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号