We help IT Professionals succeed at work.

Direct iPhone users to one site, iPad users to regular site?

n00b0101 asked
Trying to find a way to direct web site visitors using an iPhone (or mobile device) to m.mysite.com while iPad and other users are directed to www.mysite.com.  Can't really figure out how to differentiate between iPad and iPhone users?  
Watch Question

The only way you can do it is to look at the user agent string.

See here for Apple user agent strings http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones#Apple_Inc.

Check out this page for detecting the right type.

Nice site. It uses the user agent string as I suggested and it probably does it a lot better than you can write yourself.

Bookmarked :)

Top Expert 2010

You can use htaccess to redirect only iphone users to your mobile version

Just add this to your .htaccess file

RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://iphone.yoursite.com [R=301]

Other devices you might want to transfer to your mobile version:

Hope that helps
May I also suggest that another option is just to use a different CSS stylesheet based on whether your site is being accessed by an iPhone?

I have used this successfully in iPhone development to target a specific CSS only for the iPhone. These tags are specific to WebKit (the internal browser used by iPhone), so would be ignored by IE and FF (though not by Safari/ Chrome)

(see below)
<META name = "viewport" content = "width = device-width, initial-scale = 1.0, user-scalable = yes">
		<LINK media="only screen and (max-device-width: 480px)" href="iphone.css" type= "text/css" rel="stylesheet">

Open in new window