Tips & Tricks

Detect iPad using .htaccess

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.

[cc lang=”apache”]
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://your-domain.com/ipad.html [R=301]
[/cc]

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.

Shares:
  • Andrew Champ
    February 13, 2012 at 10:31 am

    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]

    Reply
  • Chris
    Chris
    February 13, 2012 at 8:25 pm

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

    Reply
  • Ryan
    Ryan
    February 29, 2012 at 1:04 am

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

    Reply
  • srhgrace
    March 11, 2012 at 8:26 am

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

    Reply

Leave a Reply

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