0

I have a .htaccess file with the following:

RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

Everything is fine and works great when viewing form a mobile phone - it detects and goes straight to the subfolder where the mobile site is located. But what I am trying to figure out is how to have a link at the bottom of the mobile site that will allow the user to view a desktop version. And when they're on the desktop version I want them to be able to get back to mobile...

Can anyone help me???

ChrisW
  • 4,970
  • 7
  • 55
  • 92

3 Answers3

0

As for the "View Desktop Version" link, that should just be an HTML modification on the mobile site, huh?

In order to keep users on the desktop site after they've selected the option though, you'll need to implement a way to track their client-side preferences, e.g., a cookie. Here's some info about adding a cookie-based condition to your rewrite rule: How to do htaccess redirect based on cookie value

Community
  • 1
  • 1
  • Do you know how I can get a view desktop link to work. If I put it in there it goes to the root folder then goes right back to the subfolder because that's what is in the .htaccess file. – Justin Wegner Jun 13 '12 at 03:02
0

Yes, use a cookie. You can set them with the [CO] flag, and interrogate these through %{HTTP_COOKIE} condition, e.g. add cond to the rule

  RewriteCond %{HTTP_COOKIE} !force_desktop

and detect the (un)set URIs to clear/set the cookie.

TerryE
  • 10,724
  • 5
  • 26
  • 48
  • Thank you for the reply. But bare with me as I don't know how to implement the cookie. If I have a separate link on the mobile site to go to the desktop version how will it know how to go back to mobile? – Justin Wegner Jun 12 '12 at 19:18
0

I wouldn't use cookies since that might not work properly for first-time visitors or users with cookies set to disabled. I would add a pre-defined GET-parameter that forces the site to go to the non-mobile version.

One example: If your domain is www.fancysite.com that could be www.fancysite.com/nomobile. For the "nomobile" URL you define an automatic forwarding in the .htaccess. Use the [L] condition for this rewrite rule so that other conditions are ignored. If the "nomobile" string is not present, your (already working) user agent detection kicks in and the user reaches the mobile site.

See these for some details (especially under "conditions"):

http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/

http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/

Jan Petzold
  • 1,561
  • 1
  • 15
  • 24