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]


  1. User Avatar
    Permalink to comment#

    Some implemention instructions would be nice.

  2. User Avatar
    Permalink to comment#

    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.

  3. User Avatar
    Rich Bradshaw
    Permalink to comment#

    Remember that the iPod touch probably wants to be redirected as well, and that it’s UA has iPod instead of iPhone…

  4. User Avatar
    Ryan Richards
    Permalink to comment#

    thanks for adding the textmate snippet link – thats a classy addition of which i’ve seen nowhere else :)

  5. User Avatar
    Richard Rudy
    Permalink to comment#

    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

  6. User Avatar
    Permalink to comment#

    cool! this might help serving responsive images as Richard says, saving some bandwidth for visitor and server both.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.