lots of tech info here

Detect iPad in PHP, Perl, JavaScript, Nginx, Apache, Lighttpd

This article shows how to programmatically detect an iPad visitor from the user-agent in PHP, Perl or JavaScript and configure it at webserver level for Nginx, Apache and Lighttpd servers.

The iPad's user-agent string for Safari is (iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10

To forward all iPad visitors from http://aruljohn.com to http://ipad.aruljohn.com, this is what to do.

Using PHP

Using Perl

Make sure this is the only print statement. Do not allow any other header to be output before this.

if (index($ENV{'HTTP_USER_AGENT'}, 'iPad')) {
    print "Location: http://ipad.aruljohn.com\n\n";

Using JavaScript

Use the navigator object in JavaScript.

if (navigator.userAgent.match(/iPad/i)) {

Using Nginx webserver

Edit nginx.conf. Use the variable $http_user_agent to match the user-agent string containing iPad.

server {
    listen      80;
    server_name aruljohn.com;
    location / {
        if ($http_user_agent ~ iPad) {
            rewrite     ^(.*) http://ipad.aruljohn.com$1 permanent;

Using Apache webserver

Edit httpd.conf, apache.conf or .htaccess and add this:

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

Using Lighttpd webserver

Edit lighttpd.conf and add this:

$HTTP["useragent"] =~ "iPad" {
    url.redirect = ( "^/(.*)" => "http://ipad.aruljohn.com/$1" )

Posted on 10 Apr 2010

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others