|
-
Aug 9th, 2011, 02:02 AM
#1
[RESOLVED] Apache RewriteRule fails to check cookie value
I'm setting a cookie value using RewriteRule statements in .htaccess for checking if my site should not redirect from the main desktop site to the mobile site (when accessed via iphone browser). The problem occurs when the first RewriteRule sets "mobile=desktop" in the cookie (from detecting "?desktop=true" in the querystring), the third RewriteRule fails to detect the new cookie value and redirect. If I reload the page again (without any querystring for "?desktop=true"), then the third RewriteRule redirects successfully.
Can anyone tell me why the third RewriteRule fails to detect the cookie value straight after it is set in the first rule? How can I fix this to work properly?
Code:
# set cookie if true querystring
RewriteCond %{HTTP_USER_AGENT} (iphone|ipod) [NC]
RewriteCond %{QUERY_STRING} (.*)desktop=true(.*)$
RewriteRule ^(.*) - [CO=mobile:desktop:example.com]
# unset cookie if false querystring
RewriteCond %{HTTP_USER_AGENT} (iphone|ipod) [NC]
RewriteCond %{QUERY_STRING} (.*)desktop=false(.*)$
RewriteRule ^(.*) - [CO=mobile:mobile:example.com]
# Redirect iPhone users to mobile website
RewriteCond %{HTTP_USER_AGENT} (iphone|ipod) [NC]
RewriteCond %{HTTP_COOKIE} !mobile=desktop
RewriteRule ^(.*) http://m.example.com/$1 [L,R]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|