Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-06-24
11
Medium Priority
?
1,384 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

722 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