How do you direct iPhone/Android browser to m.example.com?

How do you direct iPhone/Android browser to m.example.com? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How do you direct iPhone/Android browser to m.example.com? error on your web browser. Problem :


I have some special coding that only works for HTML5 browsers (simple geolocation stuff). I want to redirect iPhone and Android users to the m.example.com version of my website. How is the best way to do this?


Solution :

you can use UserAgent detection, or you can use the jQuery.support(). Since you are looking for specific functionality, you can combine the two to get what you want.



UserAgent might actually be your best bet. Do this with a .htaccess file to cut down on your http requests, and possibly flashing your main site before redirection in the case of slow connection or slow javascript performance.



You can see the (mostly) exhaustive list of mobile user agents on the wikipedia page. As you can see there are similarities between manufacturers and versions that you could look for in a regular expression.



Your question touch two parts .. redirection and html5 compatibility.



Redirection



I'm using the following .htaccess :



RewriteCond %HTTP_ACCEPT "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %HTTP_USER_AGENT "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %HTTP_USER_AGENT "mini|nitro|j2me|midp-|cldc-|netfront|mot|up.browser|up.link|audiovox" [NC,OR]
RewriteCond %HTTP_USER_AGENT "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-" [NC,OR]
RewriteCond %HTTP_USER_AGENT "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc" [NC,OR]
RewriteCond %HTTP_USER_AGENT "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone/|wap1.|wap2.|iPhone|android" [NC]
RewriteRule ^(.*)$ http://m.example.com/ [L,R=302]


For php you can use this library: http://detectmobilebrowsers.mobi/ ... but i strongly suggest using htaccess for processing time and security.



You can find some additional examples here



http://ohryan.ca/blog/2009/02/18/revisiting-mobile-redirection-using-htaccess-rewrite-rules/



Browser capabilities



As my Android phone have no problem with html5 with geolocation code. You may consider using the Modernizr Javascript Library to detect the capabilities of the client browser visiting your page.



The excellent HTML5 boilerplate template is using modernizr out of the box to support this kind of needs.



My opinion is : I suggest to use the htaccess method for everything except recent phones and browsers supported by modernizr and let Android and iPhone users be checked by Modernizr for html5 feature support and redirect the "rest" on your "without geolocation" version.



Modernizr example :



 if (Modernizr.geolocation) 
// do stuff
else
// propose mobile version



Hope this helps



If you're coding with PHP, you could use $_SERVER['HTTP_USER_AGENT'] for checking the UserAgent header, which is sent almost by any major mobile device to PHP script. Then just compare the value of this header with substr fuction to whatever it needs to have inside.



For example, Apple devices will always have 'iphone' or 'ipad' sub-strings; Android devices will always have 'android'. Almost every mobile device will have 'mobile' sub-string listed in this header.


We hope that this article has helped you resolve the iphone, android, redirects error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=