I've got 2 sites for a client. One is the mobile site, the other is the normal site. These both have seperate URLs.
Using .htaccess I've already got it working so that if you come in on a mobile, you get redirected to the mobile site. What I would like to do now is have a link on the mobile site that will take a user back to the normal site. This setting would be remembered by a cookie being set.
And thats where the problem comes in...
I can set the cookie for the mobile site but when its then redirected to the normal site, it cant see that cookie due to cross-domains and redirects right back to the mobile site.
Im trying to be clever and making the cookie placement dynamic dependant on domain and when redirecting to the normal site, setting a cookie there too to tell it not to try and redirect.
Here's the mod_rewrite code that Im working on. Have brain ache over this right now so if someone could point out where I've gone wrong or if this is even possible, that would be grand
# Write cookie if redirected
RewriteCond %{QUERY_STRING} (^|&)mredir=0(&|$)
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST}]
# redirect if mobile device && !mredir
RewriteCond %{HTTP_HOST} ^normalURL.com$
RewriteCond %{HTTP_COOKIE} !mredir=0
RewriteCond %{QUERY_STRING} !(^|&)mredir=0(&|$)
RewriteCond %{REQUEST_URI} !^/mobile/
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobileURL.com/ [R=302,QSA,L]
# point at mobile site IF !mredir
RewriteCond %{HTTP_HOST} ^mobileURL.com$
RewriteCond %{HTTP_COOKIE} !mredir=0
RewriteCond %{QUERY_STRING} !(^|&)mredir=0(&|$)
RewriteCond %{REQUEST_URI} !^/mobile/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*)$ mobile/$1 [L,QSA]
# IF mredir, redirect normal site
RewriteCond %{HTTP_HOST} ^mobileURL.com$
RewriteCond %{HTTP_COOKIE} mredir=0 [OR]
RewriteCond %{QUERY_STRING} (^|&)mredir=0(&|$)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*)$ http://normalURL.com?mredir=0 [L,QSA]
# point at normal site
RewriteCond %{HTTP_HOST} ^normalURL.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]