I have got 2 sites for any client. The first is the mobile site, another may be the normal site. These have seperate Web addresses.

Using .htaccess I have already first got it working to ensure that should you are available in on the mobile, you receive rerouted towards the mobile site. What I must do now's possess a link around the mobile site which will have a user to the standard site. This setting could be appreciated with a cookie being set.

And thats in which the problem is available in...

I'm able to set the cookie for that mobile site however when its then rerouted towards the normal site, it cant observe that cookie because of mix-domain names and redirects back towards the mobile site.

Im attempting to be clever and making the cookie positioning dynamic based upon domain so when redirecting towards the normal site, setting a cookie there too to inform it not to redirect.

Here's the mod_rewrite code that Im focusing on. Have brain pain over this at this time therefore if someone could explain where I have gone wrong or if this sounds like even possible, that might 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]