Tag: ipad

Detecting iPad Visitors: PHP, Javascript, and .htaccess

It’s been a while since I posted a tutorial on how to detect iPhone visitors on your site.  Since then, there are many more iDevices out on the market.

In some instances, it makes sense to identify and redirect iPad users to provide a unique viewing experience.


The following code can help you detect if the user is using an iPad:

Select Code
// Check for iPad
var isiPad = navigator.userAgent.match(/iPad/i) != null;

You can (and should) also do this check via PHP.


Select Code
$isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');


Lastly, once you know your web visitor is viewing the page from an iPad, you can use a simple .htaccess file to redirect the visitor to your desired location.

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

Of course, you’ll want to replace “YourDomain.com/iPad” with the intended URL.


I realize that I didn’t outline each specific step — just the essential code.  If you have any questions about these functions, just comment below.