The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other .htaccess questions about subdomain usage

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #31056

    Hello, I’ve created a subdomain ‘mobile’ for my site, and want to redirect mobile device users to that subdomain.

    I have written a bit of code for my htaccess file to redirect those devices;

    RewriteEngine On

    #redirect mobile browsers

    RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
    RewriteRule ^(.*)$ [R=301]

    RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
    RewriteRule ^(.*)$ [R=301]

    RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
    RewriteRule ^(.*)$ [R=301]

    When I try to access the site this way, however, my mobile device tells me that there were too many redirects.
    I’m very confused to say the least. Is the same as ?
    If so, how do I direct visitors to the index.html within my mobile subdomain file?

    Any help would be really appreciated. I can’t find much information on this through Google. Thanks!


    Where is this .htaccess file placed?

    When it says too many redirects I *think* it means that it just keeps redirecting because you have a catch all on the redirect even though it loads, your .htaccess file is telling it to redirect to and it does it over and over and over until it gives up.

    I’m sure someone can correct me if I am wrong though!


    Hi Mark, the .htaccess file is located in my root directory, where my traditional index.html would be.

    I’ve been messing around, and I have another question which may help me solve this…

    New to using sub-domains, I do not understand how to direct users to an index.html file for a subdomain. For instance, I was hoping that browsing to would take me to the index.html file located within the mobile subdomain folder. However, it goes nowhere. Similarly, has the same result.

    This is driving me nutters – maybe its due to the solstice lunar eclipse we’re experiencing tonight.


    I’m not a rewrite guru, but first you should check/ensure that mod_rewrite is enabled on your server. You can waste a load of time playing with .htaccess and rewrite rules, as well as make yourself go crazy!!

    Try these two, hopefully I am not far off!

    Options +FollowSymlinks

    RewriteBase /
    RewriteCond %{HTTP_HOST} !^$

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} iPhone
    RewriteRule .* [R]


    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^$

    RewriteCond %{HTTP_USER_AGENT} “iPhone|android”[NC]

    # rewrite rules here
    RewriteRule ^(.+)$$1 [R=302,NC]


    EG2 does nothing for me – EG1 gives me the “too many redirects” error. I’ll leave EG1 up for a bit – go ahead and try it out. should redirect to


    On a completely unrelated note, your contact form is a thing of beauty.


    awh shucks – thanks Mark. I like parts of it. I’ll probably redesign it once I get the blog, freebies section, about page, and mobile site up and rolling. Its feels great to get some feedback – I left a position as a General Manager for Hollister 8 months ago to pursue a career in this industry. A bit of a gamble, but its working out well – just lonely being a freelance guy.


    I feel like .htaccess isn’t the right way to approach this – perhaps a .htaccess redirect to a index.php which redirects mobile to the mobile subdirectory index.html, and everything else to the root index.html. How do companies implement this in the real world?



    Have you found a solution? I’m having the same exact issue.



    skiingtahoe – nope. It was driving me nuts and I was wasting way too much time trying to hash out different implementations. There are some device-detection services available on the web which will redirect, but I’m not about to start trying them all.

    I’ve read a few articles talking about the different ways to consider redirecting mobile visitors, but nothing covering how to dev and implement those features. If I figure this out for good, I’ll write a tutorial one day.

    Chris Coyier, if you’re reading this, a tutorial covering the “why” and “how” of mobile redirects would be awesome. When to redirect, the right way to do it (providing visitors with a link to “full-site”, premalinks, etc…), and how to do it.

Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘Other’ is closed to new topics and replies.