How do I redirect to www.subdomain?

19 replies
Hi, I'm working with an archaic stodgy domain registry who refuse to offer cpanel to their clients without a massive fee so I have to do all my redirecting manually in the .htaccess file - sigh.

I've managed to get http ://subdomain.maindomain.com to resolve but don't know the code to get ww w.subdomain.maindomain.com to resolve and the support is no help at all. I've wasted too much time on this already and not sure I want to "test" anything on this mission critical client site.

Does anyone know what I must enter in the .htaccess file to get both http and www to work with a subdomain?

Thanks.
#redirect #wwwsubdomain
  • Profile picture of the author eswariseo
    Please go threw this below link, you will get better way to fix your issues
    Free .htaccess Redirect Generator
    htaccess Redirect
    {{ DiscussionBoard.errors[7194949].message }}
    • Profile picture of the author ctsindia
      Here is the code for htaccess:

      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^subdomaindotcom$ [OR]
      RewriteCond %{HTTP_HOST} ^wwwdotsubdomaindotcom$

      In the above snippet, replace dot with a .
      {{ DiscussionBoard.errors[7194969].message }}
  • Profile picture of the author ctsindia
    You would also need to put an A record for your sub domain to point to the server IP on which your main domain resides.
    {{ DiscussionBoard.errors[7194986].message }}
  • Profile picture of the author Mr Bill
    Thanks guys.

    CTS... would your code allow people to type in wwwdotsubdomaindotmaindomaindotcom and arrive at that exact domain? So the browser displays the www? Or will it just send any requests for www to the h t t p://subdomain address and display the address without the www? Because I'd like for the www to be displayed as per a normal cpanel subdomain.

    Also, if the h ttp://subdomain is already resolving will I need to do anything to the cname records?

    Here's what is already in there...

    Code:
    RULE_1_START:
    insensitive match IN:Host into % with ^www.domain.com.au
    if  matched then goto END
    RULE_1_END:
    RULE_2_START:
    insensitive  match IN:Host into % with ^(.*).domain.com.au
    if matched then match URL  into $ with ^/(.*)
    if not matched then goto RULE_2_END
    set URL =  /%1/$1
    RULE_2_END:
    RULE_0_START:
    match IN:Host into $ with ^domain.com.au$
    if matched then
    match URL into $ with ^/(.*)$
        set OUT:Location = http://www.domain.com.au/$1
        set OUT:Content-Type = text/html
        set RESPONSE = 301
        set BODY = Moved
    goto END
    endif
    RULE_0_END:
    {{ DiscussionBoard.errors[7195230].message }}
  • Profile picture of the author viescripts
    Originally Posted by Mr Bill View Post

    Hi, I'm working with an archaic stodgy domain registry who refuse to offer cpanel to their clients without a massive fee so I have to do all my redirecting manually in the .htaccess file - sigh.

    I've managed to get http ://subdomain.maindomain.com to resolve but don't know the code to get ww w.subdomain.maindomain.com to resolve and the support is no help at all. I've wasted too much time on this already and not sure I want to "test" anything on this mission critical client site.

    Does anyone know what I must enter in the .htaccess file to get both http and www to work with a subdomain?

    Thanks.
    why aren't you trying to solve all these questions on domain registrator side?
    point the domain with aliases to DNS or IP records, you may also create a redirection for your domain name in the registrator cpanel.

    why htaccess?
    {{ DiscussionBoard.errors[7196115].message }}
  • Profile picture of the author Mr Bill
    Originally Posted by viescripts View Post

    why aren't you trying to solve all these questions on domain registrator side?
    point the domain with aliases to DNS or IP records, you may also create a redirection for your domain name in the registrator cpanel.

    why htaccess?
    Because they are no help (NetRegistry - Australians know how atrocious these guys are with support - they pointed me to a knowledge base article which was less than helpful) and these are the tools they give us. Believe me, I'd rather have spent 20 seconds in cPanel rather than the 8 hours I've spent on this today ringing everyone who's "supposed to be" in charge of the domian. The poor buyer of my mobile sites has been shoveled from one "reseller host" to another (as they all go broke on a regular basis) and now no one knows who's in charge, no one's taking responsibility and all I have is raw tools to get the job done. I don't get paid until the site is installed and working so I'm "it".
    {{ DiscussionBoard.errors[7196136].message }}
  • Profile picture of the author KirkMcD
    A Domain Registrar generally doesn't handle DNS Settings and cPanel is used in Web Site Hosting.

    And, why in the heck do you want to do something so ugly as to put www in front of a subdomain url?
    {{ DiscussionBoard.errors[7197581].message }}
    • Profile picture of the author Mr Bill
      Originally Posted by KirkMcD View Post

      A Domain Registrar generally doesn't handle DNS Settings and cPanel is used in Web Site Hosting.

      And, why in the heck do you want to do something so ugly as to put www in front of a subdomain url?
      Thank you oh so much for your input Kirk :rolleyes:, I've been doing this for 15 years so I know the difference between a name registrar and a host thanks. In this case the registrar is also providing hosting. This occurs quite often. In fact most name registrars these days also offer hosting. You should know this.

      Since when is www ugly? Most normal business people know that having a www in front of a URL automatically tags it as a web address and catches the prospect's eye, leaving the www out of a web address (on a business card for example) is what would make a URL ugly - not the other way around. In this case the client wants to print his mobile web address in his literature and wants www. But so do I. I think it makes it look normal.

      Got any other useful comments? Would you like to address the actual questions in my thread or did you just wake up all angry today?
      {{ DiscussionBoard.errors[7200483].message }}
      • Profile picture of the author viescripts
        Mr Bill, if you wish to move on this would be very helpful to see your registar website DNS management page. Same thing with DNSes can be done in your cpanel, if it's activated for your personal cpanel account.
        Is your cpanel run by Cpanel Inc not just a custom panel?

        I could do for you a simple tutorial how to modify DNSes and what they should look like.

        But, I have a question:
        not very clear for me what you have and what you want.
        From what I understood you have a subdomain, you can achieve with url
        http : / / subdomain at domain at com
        and you want this to work at the same time with url
        http : / / www at subdomain at domain at com

        Did I get is right? This question is solvable only by correct DNS records setup, htacces won't help.
        {{ DiscussionBoard.errors[7202168].message }}
  • Profile picture of the author Mr Bill
    There is no cPanel. If there was a cPanel I'd been able to do this in 20 seconds like I've done a thousand times. This is very bland unfriendly console with no direct instructions on how to do this in the KB.

    Here is the htaccess section and from the menu you can guess why I think this is the area I'd be adding the www redirect. It's the area I had to use to create the initial subdomain.



    I have access to Zone management as well if that helps... here are my choices...

    To add a record to this zone click on a type

    A or AAAA or CNAME or MX or NS or TXT or SPF or SRV

    Here's my admin options page...


    This is the server settings page...
    {{ DiscussionBoard.errors[7202231].message }}
    • Profile picture of the author viescripts
      So you create a A name for your
      subdomain at domain at com
      and a CNAME for
      www at subdomain at domain.com and point it to subdomain at domain at com

      Is it what you were looking for?
      {{ DiscussionBoard.errors[7202265].message }}
  • Profile picture of the author Mr Bill
    I've never had to work with a names or cnames or zones or any of this before (and never will again without charging an hourly rate for all this massive hassle) but what I want to do is allow people to type in a normal web address like wwwdotsubdomaindotdomaindotcom and have it go to the subdomain and have the wwwdot stick to the front of the address as per normal. I don't want it to redirect to http ://subdomain...etc (though at this stage of extreme frustration I would accept that as a solution and move on), I just want it to work with a normal www and go to a www.

    Thanks for your help. I appreciate it.
    {{ DiscussionBoard.errors[7202299].message }}
  • Profile picture of the author Mr Bill
    Here's my A record screen


    and here's my CNAME screen


    Not sure I understand what "Do not enter a fully qualified name. Name will automatically be added to parent domain" means though. If it was my own domain I'd just play until I got it right but I can't afford to break anything on this existing high traffic website.

    Do you know what I need to put where? The subdomain gets it's files from a folder called "mobile" which sits in the root of the main domain (as normal - like when I build a subdomain in cPanel).
    {{ DiscussionBoard.errors[7202355].message }}
    • Profile picture of the author viescripts
      Looks like you should do the following:

      A record
      Name - subdomainname
      Host - websitename.com

      CNAME
      Name - www
      Host - subdomainname.websitename.com
      {{ DiscussionBoard.errors[7202782].message }}
  • Profile picture of the author Mr Bill
    Ok, the subdomain already works on a http level with the htaccess mods (from above) so do I only need to do the cname part to add the www to the already existing subdomain?
    {{ DiscussionBoard.errors[7202798].message }}
    • Profile picture of the author viescripts
      Originally Posted by Mr Bill View Post

      Ok, the subdomain already works on a http level with the htaccess mods (from above) so do I only need to do the cname part to add the www to the already existing subdomain?
      that's all right, but with a little modification

      instead of this:

      CNAME
      Name - www
      Host - subdomainname.websitename.com

      use rather this:

      CNAME
      Name - www.subdomainname
      Host - subdomainname.websitename.com

      the second thing will most probable work, because this name means everything before the domain name.
      {{ DiscussionBoard.errors[7207389].message }}
  • Profile picture of the author urwithsteve
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[7203071].message }}
    • Profile picture of the author Mr Bill
      Originally Posted by urwithsteve View Post

      search on google with the help of Google Websmaster tool
      :rolleyes: thanks.
      {{ DiscussionBoard.errors[7203137].message }}
  • Profile picture of the author Mr Bill
    Ok, thanks. I've tried that (the second thing) and am getting HTTP 400 Bad Request but it might be just taking a while to resolve and replicate around the world or something. I'll check it again in the morning and let you know if it worked.
    {{ DiscussionBoard.errors[7208300].message }}
    • Profile picture of the author viescripts
      Originally Posted by Mr Bill View Post

      Ok, thanks. I've tried that (the second thing) and am getting HTTP 400 Bad Request but it might be just taking a while to resolve and replicate around the world or something. I'll check it again in the morning and let you know if it worked.
      it usually resolves in 10-30 minutes. Just run in google ping website and ping your subdomain with www, should show your domain ip or a error.
      Let me know if works or not, just interesting.
      {{ DiscussionBoard.errors[7213072].message }}

Trending Topics