Code Snippet
iPhone Catcher
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^index\.html$ http://www.mobile.mydomain.com [L]
RewriteRule ^/$ http://www.mydomain.com/index.html [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^index\.html$ http://www.mobile.mydomain.com [L]
RewriteRule ^/$ http://www.mydomain.com/index.html [L]
</IfModule>
Some implemention instructions would be nice.
It looks like all you would have to do is create a .htaccess file on the root directory of the site you would want to redirect for iPhones. Copy the above code into the file and change the fourth line where it says “http://www.mobile.mydomain.com” to where you would want it to redirect to. And then create whatever alternate page the iPhone would go. Also make sure that on the fith line the “www.mydomain.com/index.html” is changed to your domain.
Remember that the iPod touch probably wants to be redirected as well, and that it’s UA has iPod instead of iPhone…
thanks for adding the textmate snippet link – thats a classy addition of which i’ve seen nowhere else :)
I’m thinking this may be useful to serve responsive images if you add the filter for image file types and increase the amount of browsers in the query string, or or just query user agents that contain the string “mobile”
I know User Agent strings aren’t’ the best way to detect mobile browsers, but realistically people spoofing their user agent string are edge cases
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.