Forums

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
    Posts
  • #31056
    aaronsilber
    Participant

    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 ^(.*)$ http://mobile.mysite.com [R=301]

    RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
    RewriteRule ^(.*)$ http://mobile.mysite.com [R=301]

    RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
    RewriteRule ^(.*)$ http://mobile.mysite.com [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 http://mobile.mysite.com the same as http://www.mysite.com/mobile ?
    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!

    #69373
    TT_Mark
    Member

    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 rule..so even though it loads http://mobile.mysite.com, your .htaccess file is telling it to redirect to http://mobile.mysite.com 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!

    #69342
    aaronsilber
    Participant

    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 http://mobile.mywebsite.com would take me to the index.html file located within the mobile subdomain folder. However, it goes nowhere. Similarly, mobile.mywebsite.com/index.html has the same result.

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

    #69304
    shaun101
    Member

    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!

    EG1
    Options +FollowSymlinks

    RewriteBase /
    RewriteCond %{HTTP_HOST} !^http://yourdomain.com$

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} iPhone
    RewriteRule .* http://mob.yourdomain.com/ [R]

    EG2

    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^http://yourdomain.com$

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

    # rewrite rules here
    RewriteRule ^(.+)$ http://m.mysite.com/$1 [R=302,NC]

    #69314
    aaronsilber
    Participant

    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. http://meetaaronsilber.com should redirect to http://mobile.meetaaronsilber.com

    #69264
    TT_Mark
    Member

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

    #69140
    aaronsilber
    Participant

    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.

    #69111
    aaronsilber
    Participant

    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?

    #67347
    skiingtahoe
    Member

    Aaron,

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

    Thanks!

    #67356
    aaronsilber
    Participant

    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.