Comments on Apache2: How to Redirect Users to Mobile or Normal Web Site Based on Device Using mod_rewrite
Since the massive rise of mobile devices, smartphones, and tablets like the iPhone, iPad, Android phones and tablets, BlackBerries, etc. you might have considered creating a mobile version of your website. This tutorial explains how to configure Apache to serve the mobile version of your website if the visitor uses a mobile device and the standard version if the visitor uses a normal desktop PC. This can be achieved with Apache's rewrite module.
13 Comment(s)
Comments
Please don't do this without a way of giving the visitor to your site the option to override. Tablets are as capable as desktops and it's very frustrating when you're stuck viewing a cut-down site designed for a 3 or 4 inch screen on a device with a 10 inch screen.
Anonymous is right. Forcing this on the user is like a cafe that checks what kind of cup you brought in and gives you the drink they think best fits your container. Maybe I like tea in my coffee mug (or hot cocoa with cinnamon). Better to let me decide, and when I come back next time (because of your friendly service and nice tea), ask me briefly, "the usual?" I should always have the option to change my mind, don't nag, just give me choices and remember me from last time if at all possible.
Yes! It´s true.
And i´ve been such a time frustrated with all the m.site. I got a Xoom Tablet with Android 3 and became less frustrated when i discovered that the Opera 5 Navigator could simulate a desktop connection. There´s an option to choose between tablet and desktop mode. I agree that Tablets has the same power that most netbooks and the main difference is that netbooks are more suited to editing uses while tablets are more suited to viewing.
Great tutorial - I have tried this on a website under construction and it works as expected for Iceape as well as for HTC smartphone. However I do agree with the previous comment - iPads have 1024x768 px screens so should (?) display standard web pages correctly and may have to be excluded from the list of small devices. A problem may arise with Android which could be used for smart phones as well as for tablets. Not sure if this is workable other than by excluding Android as well, and provide a link at top of page to the small-screen pages. In which case every device could be provided with the choice, but necessitates small-screen devices downloading unsuitable pages initially.
The lines that are like:
RewriteRule ^$ http://m.example.com/ [L,R=302]
Feature a matcher that will never match anything.
It should be something like
RewriteRule ^/(.*) http://m.example.com/ [L,R=302]
or
RewriteRule ^(.*)$ http://m.example.com/ [L,R=302]
I think the best way to redirect mobile is with "Apache Mobile Filter" an open source and free project below an example:
PerlSetEnv AMFMobileHome /usr/local/AMF PerlSetEnv AMFProductionMode true PerlSetEnv ServerMemCached localhost:11211 PerlTransHandler +Apache2::AMFLiteDetectionFilter RewriteEngine on RewriteCond %{ENV:AMF_ISMOBILE} ^true* RewriteRule ^(.*)$ http://m.foo.org [R=301,L]
you can also use AMFDetectRightFilter, AMF51DegreesFilter or AMFWURFLFilter is depend of which device repository you want to use.
For more detail: http://www.apachemobilefilter.org
I found the codes in this page the most useful. You guys rock! I was finally able to get my site to recognize mobile devices, and redirect them over to a mobile site, I created. However, I have one question. For tablets, like the HP TouchPad, which ALSO runs on WebOS, I'm thinking I may want to create a link that would disable this redirect, but I can't think of how to code this. Can anybody provide me any input as to how I might incorporate a link on my mobile webpage, that if clicked, will bypass this redirect and take them directly back to my non-mobile optimized site?
you can have a glance at my article regarding this issue,
http://vigram-software-generals.blogspot.in/2010/09/desktop-to-mobile-site-switching-apache.html
thanks for the info
Just an update of AMF now there is apache module mod_amf that do easily this work.
Looks like somebody screwed up this article, the user agents are the same for both htaccess files?? LOL that makes no sense!
The list of agents is the same, but one of the conditions starts with bang and the other doesn't. The conditions match in exactly conplementary situations.
above code is not working...