I am writing some code that redirects to a mobile verision of a website UNLESS a cookie has been set.
There is a link on the mobile site, "Go to desktop site". It's target is the desktop site with the GET variable, "noredirect=1".
The following is the code in the root .htaccess file on the desktop site. It checks for the GET variable and then sets a cookie if it exists, then skips the next rule.
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=1(&|$)
# Set a cookie to say we want to stay on the desktop site
# and skip the next rule so
# that the below mobile rule does not redirect
# (cookie cannot be set AND read in one request)
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=1]
The skip flag does not seem to be working. Below this code I have a few RewriteConds and one RewriteRule:
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\smredir=1(;|$)
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera|mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?((?!www\.)[^.]+)\.([^.]+\.[^.]+)$ [NC]
RewriteRule ^$ http://m.%1.%2 [L,R]
Is the skip flag meant to still work when the next rule has conditions preceding it?
Also, my main question: Is the syntax for the skip flag correct and can it be done in the same line as where one is setting a cookie?
I've tried these 2 combinations:
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=1]
and
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST}] [S=1]
Neither give any errors but the skip flag still does not work.
Help would be appreciated, thanks.