Solved

Using htaccess to send visitor to mobile site - but not for ipad or android tablets

Posted on 2013-06-24
11
1,347 Views
Last Modified: 2013-06-29
Hello

One of my sites has a mobile version and I want to direct only cell phone type devices to that site. I want people with ipads or android tablets to see the regular (desktop) version of the site.

Perhaps by device resolution?  For example I would want my 7 inch Galaxy Tab 2 to see the desktop version.

The specs on my Galaxy are as follows:  1024 x 600   So I guess any device with a 600 resolution or higher should see the desktop version.  

Here is a snippet from my current htaccess file.   How can I modify/fine tune it per my above request.

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

Open in new window


Thanks!

Rowby
0
Comment
Question by:Rowby Goren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 21

Assisted Solution

by:Julian Matz
Julian Matz earned 250 total points
ID: 39273665
Hi rowby,

It's not possible for Apache or htaccess to determine the users' device resolution. You could do it with a client-side scripting language like JavaScript, but not with htaccess.

Using JavaScript and jQuery, you could do something like this:

if ( $(window).width() < 600 ) location.href = "http://m.example.com/";

Open in new window

0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 39273673
Short answer: you can't.

Long answer: you sort of can, but there is no guarantee it will work as expected.

As you might have gathered from the RewriteCond you have now, "device" detection is actually user agent detection.  The user agent is (typically) the browser being used.  The device itself does not usually send any information about its specifications along with an HTTP request, so you have no way to target those specific devices from the request alone.  The most you can hope for is to target the user agents commonly used on those devices.  Even then, you're still going to miss the users that install custom browsers, or otherwise modify their user agent strings (looking at you, Opera).  

This also means, as pointed out by JulianMatz, that Apache has no way to detect screen resolution (or other hardware configurations) on the client side.  Javascript solutions such as jQuery, et al, are your only avenue in that context.

You can find lists of user agent strings easily through Google.  Here is one example.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39273751
Hi routinet and julianmatz,

Fascinating!  

And that Google link is helpful.

Then let me rephrase the question, in a selfish way  I'd like to at least be able to see the site on on own 7 inch Galaxy Tab 2 when I am without my laptop -- so I can keep track of issues on the site.

That way I can monitor my site via the the desktop version.  (By default when  mobile device accesses the site a mobile version is used, and I don't have any control over that. But I can modify the htaccess file.

I guess I can gat that to work for my galaxy, Right??  :)

So I guess I need to figure out the "user agent" that my  7 inch Galaxy Tab 2 uses.   And put that  into the .htaccess file.

(Note, the way the site is setup we can't use a javascript solution).

I will dig through the google list to see if I can find my Galaxy.  I can use any browser that I can download from the Google Playstore.  

I'll revisit this tomorrow and see what I can do.

Thanks.  Your explanations are appreciated.   And of course I will be splitting points.

Rowby

P.S.  I  came across this link via go google search:   Samsung
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 21

Expert Comment

by:Julian Matz
ID: 39275249
Hi Rowby. You can visit this URL on your tablet to find out exactly what user agent string is being detected for your device:

http://www.netlink.ie/tools/user-agent.php
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39275305
Hello

I found a Adroid ap plugin for Dolphin browser that lets me switch from a mobile view to a desktop view.  So that is one solution I am using so I can see the desktop of a web page on my android.  So that is certainly a workaround.  (The free ap is called Dolphin Desktop Toggle, via Play Store.  It has mixed reviews, but works fine on my Galaxy tablet.)

I am curious to know more about the "User Agent".  Is it possible to detect a specific mobile device via the .htaccess file. I am thinking specifically about my own Galaxy Tablet.  If there is some unique identification (unique only to my tablet) and in fact it is a "User Agent" can that unique user agent be added to the htaccess file -- so I myself (using that specific tablet) will be able to deliver a desktop view instead of the mobile version of the site).  

To explain, the whole issue of being able to view the desktop version of the site was motivated by my need to monitor the desktop version of the site, whenever I am away from my office so I can view it easily on my tablet.  

The dolphin ap will do it, but I am still curious (and want to be educated) about the abilities and limitations of User Agents -- as we move more and more into a mobile / tablet world.

Thanks for continuing the discussion and solutions, and yes, I will be splitting points.

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39275418
Hi  julianmatz

I missed your earlier comment regarding detecting my device.  I'll review that link...

Thanks!

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39275434
Ok.  I found on that link that my samsung user agent accessed by the android firefox bowser is as follows:

Your user agent string is:
Mozilla/5.0 (Android; Tablet; rv:21.0) Gecko/21.0 Firefox/21.0

With that info can I set something in the htaccess file to show the desktop version of the site instead of the mobile version -- at least it  would be covering me when I check out the site via my mobile galaxy tab firefox browser????  

Rowby
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 39275567
Try this:

RewriteCond %{HTTP_USER_AGENT} !^Mozilla\/5\.0\ (Android;\ Tablet;\ rv:21\.0)\ Gecko\/21\.0\ Firefox\/21\.0
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobile.webitel.com/ [L,R=302]
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 39275698
Hi

I will try this later tonight and report back :)


RewriteCond %{HTTP_USER_AGENT} !^Mozilla\/5\.0\ (Android;\ Tablet;\ rv:21\.0)\ Gecko\/21\.0\ Firefox\/21\.0
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobile.webitel.com/ [L,R=302]

Rowby
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 250 total points
ID: 39277173
>>> I found a Adroid ap plugin for Dolphin browser that lets me switch from a mobile
>>> view to a desktop view.  So that is one solution I am using so I can see the desktop
>>> of a web page on my android.  

Again, this is based on user agent detection.  The plugin is probably manipulating the user agent string based on your site viewing preferences.

>>> I am curious to know more about the "User Agent".  Is it possible to detect a specific
>>> mobile device via the .htaccess file.

As I said before, there is no way to detect the *device* being used, only the *browser* running on that device.  Your site is not detecting your Samsung tablet, but rather the generic mobile Firefox user agent string.  Examining the actual string should make this pretty clear - it identifies "Android" (OS), "Tablet" (architecture), "Gecko" (rendering engine), "Mozilla" (standards implementation), and "Firefox" (application).  

In my previous post, I mentioned Opera in the context of a browser that manipulates the user agent string.  The desktop version of Opera allows a user to supply any string they wish through a standard configuration item.  I would guess that the mobile version allows the same.  Try it out.

The rule set you are trying is probably not a good idea.  As written, EVERY mobile device running Firefox mobile v21.0 will not be redirected.  Also, once Firefox goes through its next upgrade cycle, your rule will no longer work.  

A better option is to detect a specific query string operator.  For example:
RewriteCond %{QUERY_STRING} !force_desktop_rendering=1 [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^/?(.*)$ http://mobile.webitel.com/$1 [L,R=302]

Open in new window

When you wanted to see the desktop version of your site, then you would browse to http://www.webitel.com?force_desktop_rendering=1.  This does have the disadvantage of having to change the URL for every request you make, but it would limit this redirection to only requests using the customized query string.
0
 
LVL 9

Author Closing Comment

by:Rowby Goren
ID: 39286844
Hello

I've tried the various solutions, including the link to force desktop.  I'll be using the force desktop url.   The other examples and explanations of the reality of mobile detection will help me as we move further into the mobile internet world.

THanks!

Rowby
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question