Detect iPhone & iPad by .htaccess file.

Now a day’s almost all sites are responsive for all screen size devices. But in some cases we need to create sub domains or new domains for iPad and iPhone. If want to redirect you site to another domain in case of iPhone or iPad then you can write code in you .htaccess file.

 

For iPhone.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^index\.html$ http://www.mydomain.com/m [L]
RewriteRule ^/$ http://www.mydomain.com/index.html [L]
</IfModule>

For iPad.

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

These methods as easy and search engine friendly.

 

 

Note: This trick will work only on Apache server.

Written by Ranjeet Jha

Ranjeet Jha

Hey there! My name is Ranjeet. I’m a Web Designer & Front-end Developer. I design, code, build & promote all things HTML5, CSS3, JavaScript & jQuery. In this blog you will find solutions of day to day problems faced by you.. Enjoy Coding..

Leave a Reply

Your email address will not be published. Required fields are marked *