Redirecting iPhone, iPad and Mobile Users

With the iPhone pinned for release this Thursday (June 24th) in the States, UK, France, Germany and Japan, webmasters are becoming more aware of developing websites with mobile users in mind. Many online retailers are creating optimised mobile versions of their websites and redirecting iPhone, Blackberry and Palm users to these mobile friendly versions.

There is a very simple way of doing this just by tweaking the site’s .htaccess to redirect these mobile users to a sub-domain:

#redirect iPhone, Blackberry and Palm browsers
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]

Redirecting the iPad

As well as mobile user you may also wish to redirect iPad users to a sub domain optimised for iPad viewing, you can do this by adding the following code to the website’s .htaccess file:

{code type=html}
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]
{/code}

Leave a Reply