Reputation: 5135
I have a site w/ a simple .htaccess rule that checks if the user is on a mobile browser and if so redirects them to our mobile site. problem is - if they decide they want to go to the regular site (and click a link that takes them there) they will eventually get back to the mobile site, b/c our .htaccess rule will catch them and redirect.
Is there an easy way, w/out modifying to much code that will allow them to "persist" on a regular site even though they have a mobile browser?
if thats not possible - is there a simple minimal solution to make this work in the code?
Upvotes: 3
Views: 247
Reputation: 279
You can skip all the cookie stuff and check the http referrer in the http header. If the referrer is your mobile site then don't redirect them to the mobile site.
Hope that helps.
PS : I'd be interested to see your .htaccess for detecting mobile devices. How reliable is that ? Does it redirect many tablets accidentally ?
Upvotes: 0
Reputation: 39389
Set a cookie or session parameter containing the user's choice of override.
Upvotes: 0
Reputation: 57316
Following on from my comment, you can do the same in .htaccess by checking %{HTTP_REFERER} in mod_rewrite. I'm not sure how you do the redirect currently, but you can probably combine the two parts. So you'd end up with something like this:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://mobile.mydomain.com
RewriteCond %{HTTP_USER_AGENT} [your check for mobile browser]
RewriteRule ^(.*)$ http://mobile.mydomain.com/$1 [R=301,L]
Note that I haven't tested this, so the syntax may be a bit wrong, but it should get you started.
Upvotes: 0
Reputation: 21466
What I do is provide a link to the full-site on the mobile site. When the link is tapped, I set a cookie [with a very short lifetime] that lets the regular website know not to redirect.
The redirect to mobile is handled by PHP, not htaccess, on the regular site. The PHP checks for the cookie, and if not found, redirects to the mobile. The regular site also provides a link to the mobile site that destroys the cookie.
Upvotes: 4