Possible Duplicate:
Mobile Redirect using htaccess
Currently I have a regular website, utilizing LAMP. I'd like to add a redirect for mobile devices to a subdomain, something like: m.mydomain.com
There's going to be some content differences between the content for PC and mobile devices.
What is the best way to do that? Can it be done with .htaccess file or do I need some sort of PHP script?
Thanks.
I think .htaccess would be the fastest. you might put something like this in your htaccess file.
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://m.mydomain.com/$1 [L,R=302]
Hi Santa I found this:
if( navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/)
){
// some code
}
Source: What is the best way to detect a mobile device in jQuery?
Those answers will work fine until you want to separate tablets from mobiles. To get a better match you'll need something like Handset Detection (disclaimer : my startup) which can separate out devices by class (tablet/console/mobile). You can detect serverside with an API kit or on device with Javascript.