1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess redirect working with PC and iPhone, but not with Android

Discussion in 'Apache' started by Code-a-holic, Sep 20, 2016.

  1. #1
    Hello,

    I'm trying to redirect mobile users to a "m." subdomain and desktop users to a "www." subdomain.
    The idea however is that if the user provides the subdomain manually, he won't be redirected.
    So, the redirection should be done only when no subdomain is specified.

    #Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    #AllowOverride all
    
    # Force “m.domain.com” for mobile devices instead of just “domain.com”
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|symbian|midp|wap|phone|pocket|mobile|pda|psp|googlebot-mobile" [NC]
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
    RewriteCond %{HTTP_HOST} !^m\.domain\.com [NC]
    RewriteRule (.*) http://m.domain.com/$1 [R=301,L]
    
    # Force “www.domain.com” instead of just “domain.com”
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
    RewriteCond %{HTTP_HOST} !^m\.domain\.com [NC]
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    Code (ApacheConf):
    For a reason that I don't understand, when trying to access the domain (without specifying any subdomain) my smartphones running Android are not doing the redirection and display an "Unvailable page" error message, telling that the web page is temporary unreachable or was moved to a new web address.

    The redirection to the www subdomain works perfectly on a desktop.

    The strange is that if I comment out the lines intended to mobile devices, the redirection to the www subdomain becomes effective on an iPhone but not on Android.
    With Android is no redirection at all.
    Now, if I access the website on Android using the "www." prefix, the site displays.
    If I then remove the "www." prefix and try to access the page again, Android adds the "www." in the address bar. However the error message for an unavailable page remains.

    Thank you very much for your help.
     
    Code-a-holic, Sep 20, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Dunno what the exact problem is, but using a separate subdomain (like m.) for mobile is a bad design choice, and also completely unnecessary if you code the site properly.
     
    PoPSiCLe, Sep 21, 2016 IP
  3. Code-a-holic

    Code-a-holic Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Please don't tell if something is good or bad thing.
    I had reasons doing it so and I don't believe it was a bad thing in this case.
    One of the issue could come from the native browser on Android which seem not accepting redirections.
    Firefox Fennec is able to redirect, but seem always wanting the "www." even when setting a unique redirection to "m.".
     
    Code-a-holic, Sep 21, 2016 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Of course I will tell you if something is bad.
    What reasons? I would like to hear the reasons for using an m-subdomain - please enlighten me to your genious solution to something that has been a bad practice for years?
     
    PoPSiCLe, Sep 23, 2016 IP
  5. Code-a-holic

    Code-a-holic Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    This is off-topic, but to answer PoPSiCLe there are several reasons why I chose using subdomains:
    • The need for both the mobile and the desktop version of the site being readable from PC or from a mobile device
      (so that one can see how both versions will display when editing them on PC or the ability to also check the desktop version displays if a problem occurs when being away from the office and without computer)
    • The easiness of editing the URL to switch between both versions, just replacing the "www" by "m" and vice versa.
    • Both versions are based on a CMS located in the same folder, but the structure of the site is not the same. For instance, some pages of the desktop version are agregating contents from sub-pages, whilst the mobile version displays links to those sub-pages. The mobile version also has a shortcuts menu that the desktop version does not have.
    • The two layout are completely different (no adaptative CSS).
    • Not wanting sub-folders in the URL.
    • Not wanting extra GET parameters in the URL.
    The relationship between the pages was mentioned using <link /> elements, following Google's advices for Separate URLs:
    https://developers.google.com/webmasters/mobile-sites/mobile-seo/separate-urls?hl=en

    I find your answer both ironic and dogmatic:
    Companies like FastMail (a top of the line mail hosting) are still using an "m." subdomain for their mobile version. I also know major public transportation companies --high tech ones-- using an "m." subdomain for their mobile versions.
    All of them are all except newbies. If a "m." subdomain was a so bad solution they wouldn't have done this choice.

    I don't know to what you're thinking. Responsive design?
    The website I'm telling is really like a dedicated website, but with the huge benefit that the data (database + files) are not duplicated.
    It offers two ways to access the same data. So, it is more high-end than a standard responsive design website.

    I would have prefered such debate through private messages as we are diverging from the topic.

    I believe part of the issue is coming from the server configuration that the shared hosting uses, as I have difficulties redirecting to something else than the "www" subdomain.

    Another part of the problem seem being Android preventing redirections to another (sub-)domain, maybe for security reasons.

    I think I'm going to install some script to suggest the mobile version if the user is accessing the website with android/iOS for the first time and use a cookie to store the user choice. I also added a hard link on the homepage to the mobile version.
     
    Code-a-holic, Sep 24, 2016 IP