How to detect iPhone Browser in Wordpress and redirection using htaccess ?

by Aky Joe on February 24, 2010

WooThemes - Made by Designers

Since the evolution of the Smart Phones like iPhone, BlackBerry, etc. people have started surfing internet over smart phone browser. But websites like Yahoo Mail, Gmail, Twitter, Facebook, etc. consumes a lot of bandwidth and third party platform dependencies like Java, .Net, etc., which are usually not compatible with most of the smart phones.

image

But, being the most popular and most visited sites, cannot just compromise over the mobile browser compatibility issue. Hence, these Social Media Companies have developed a light mobile version for the main website, which when where detected a phone browser gets redirected to mobile version of the actual website. The detection of a smart phone and then redirection is done usually at hosting server and for Apache Web Server, using the .htaccess file.

Below tutorial coming is for the administrators having mobile version and want to redirect website visitors to mobile version website within the domain or outside the domain.

Note: Before attempting any changes, kindly back-up your Wordpress Files and Database, for quick restoration.

1. How to detect and redirect iPhone visitor to a sub-domain with .htaccess file.

   1: #Detect and Redirect iPhone Visitor

   2: RewriteEngine on

   3: RewriteCond %{HTTP_USER_AGENT} iPhone

   4: RewriteRule .* http://mob.yourdomain.com/ [R]

   5: #End of Code

In the above code, line number 3 detects the http_user_agent as iPhone, and further on line number 4, redirects the client to specified sub-domain, http://mob.yourdomain.com

2. How to detect and redirect iPhone visitor to a sub-directory with .htaccess file.

   1: #Detect and Redirect iPhone Visitor

   2: RewriteEngine on

   3: RewriteCond %{HTTP_USER_AGENT} iPhone

   4: RewriteCond %{REQUEST_URI} !^/mobile-version/

   5: RewriteRule .* /mobile-version/ [R]

   6: #End of Code

In the above code, line number 3 detects the http_user_agent as iPhone, and further on line number 4 it fetches the sub-directory URI, and line number 5, redirects the client to the specified sub-directory, http://yourdomain.com/mobile-version/

The above tutorial concludes to detect only for iPhone Browser and Redirect the Visitors. I’ll write soon for Nokia, Blackberry etc. phone browsers to bridge perfection.

For any queries and further assistance required, post comment as your feedback.

Related posts:

  1. htaccess code http_user_agent of Multiple Phone Browsers for Wordpress Blogs
  2. Wordpress Security: Disable directory browsing using htaccess on Apache Web Server
  3. Improve Performance by Image Caching of Wordpress Blog using htaccess trick
  4. How to Password Protect Web Directories using htaccess ?
  5. Wordpress Security: Restrict wp-content and wp-includes on wordpress using htaccess

Wpfreelancer

Leave a Comment

Previous post:

Next post:

.