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 ^(.*)$ http://your-domain.com/ipad.html [R=301]
  RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
  RewriteRule ^(.*)$ http://your-domain.com/ipad.html [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:

  • http://andrewchamp.com/ Andrew Champ

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

    RewriteCond %{HTTP_USER_AGENT} ^.*(iphone|android).*$ [NC]
    RewriteRule ^(.*)$ http://your-domain.com/ipad.html [R=301]

  • Chris

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

    • http://andrewchamp.com/ 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.

      http://mobiledrupal.com/simple-apache-configuration-file-mobile-device-detection

      • http://www.xpertdeveloper.com Avinash

        Agreed… :)

  • Ryan

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

    • http://www.xpertdeveloper.com Avinash

      Here platform refers to OS?

  • http://buy-new-ipad.com/ srhgrace

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

    • http://www.xpertdeveloper.com Avinash

      yes it will work…