Detect iPad using .htaccess

  • Avinash
  • 8
  • Feb 12, 2012
  • Tips & Tricks

Here is the small trick with which you can detect the iPad using htaccess file and make the redirection accordingly.

This will be very useful when you are about to create a separate page for iPad users and want then to redirect.

Have a look at below code block which detects the iPad using htaccess file and redirecting to separate page for iPad.

RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$ RewriteRule ^(.*)$ [R=301]
  RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
  RewriteRule ^(.*)$ [R=301]

You can see that this code uses one of the available server variable which is User Agent and checking for the ipad using regular expression. If that condition satisfies then it will perform the redirection step just below it.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • Andrew Champ

    If you want to detect multiple devices you can use this:

    RewriteCond %{HTTP_USER_AGENT} ^.*(iphone|android).*$ [NC]
    RewriteRule ^(.*)$ [R=301]

  • Chris

    Oh boy, bad practice. You CSS to deliver the appropriate content to your devices.

    • Andrew Champ

      Chris, using .htaccess to detect a device is not bad practice. Now if you don’t give an option to view the full site, then you’re using bad practice.

      Just using CSS and not allowing someone to view the full site would be ‘bad practice’.

      Here’s a method via .htaccess that does user agent detection and allows the user to view the full version of the site if they wish.

      • Avinash

        Agreed… :)

  • Ryan

    How do you forward to different sites depending on different platforms?

    • Avinash

      Here platform refers to OS?

  • srhgrace

    Thanks for the tips, will the same trick works for the new ipad?

    • Avinash

      yes it will work…