redirect iPhone, iPad and iPod users to a smart phone friendly site. Thanks to http://www.htaccesstools.com
DETECT AND REDIRECT IPHONE
Use iPhone detection and redirection to target your iPhone users.
So you want detect iPhone users on your website and redirect them to a specific page or version of your site. Here is how to redirect iPhone traffic with .htaccess:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteRule .* http://iphone.example.com/ [R]
The code will redirect iPhone users to a iPhone specific site on iphone.example.com. Or if you want to redirect to a sub directory of your site, ie example.com/my-iPhone-site/, you should use the following code:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/my-iPhone-site/
RewriteRule .* /my-iPhone-site/ [R]
Thanks to Steve Stedman for this tip.
How iPhone detection and redirection works
The htaccess code works by examining the HTTP header “User-Agent” which all browser send. iPhone sends a User-Agent header similar to this one:
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3
As you can see the text contains “iPhone”, and thats how you know its an iPhone user.
- 0 Пользователи нашли это полезным