Please help redirect subdomain via htaccess

Discussion in 'Apache' started by JasMate, Dec 31, 2007.

  1. #1
    I have put this code into my htaccess but it won't redirect blog.mydomain.com to mydomain.com
    Anyone know how I can get it working?
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^mydomain.com
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301]
    
    Code (markup):

     
    JasMate, Dec 31, 2007 IP
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This code looks okay. Is the blog subdomain correctly defined ? What do you get when you try to go to blog.mydomain.com ?

    Jean-Luc
     
    Jean-Luc, Dec 31, 2007 IP
  3. JasMate

    JasMate Active Member

    Messages:
    2,592
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    90
    #3
    I get this:
     
    JasMate, Dec 31, 2007 IP
  4. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It seems that your subdomain is not correctly defined. Check the control panel of your host. If you are lucky enough to use cPanel, there will be a "Subdomain" icon where you can easily define new subdomains.

    I do not understand why you want to add this subdomain, just to redirect it to the main domain though.

    Jean-Luc
     
    Jean-Luc, Dec 31, 2007 IP
  5. JasMate

    JasMate Active Member

    Messages:
    2,592
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    90
    #5
    First thanks for your advice :)
    I don't want to add the subdomain, it is already there, well kinda, you see this domain has been parked for some time and I have finally decided to develop it but I see that google still has the "blog" subdomain cached, thus I want to redirect it to the main domain to help with seo and any traffic that may be going (or should I say trying to go) to the old subdomain.
    You get me?
     
    JasMate, Dec 31, 2007 IP
  6. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yep, very clear!

    Creation of new subdomains is very much host dependent. Some hosts limit the number of subdomains you can create. Ask your hosting company, if my comments don't solve the issue.

    Jean-Luc
     
    Jean-Luc, Dec 31, 2007 IP
  7. JasMate

    JasMate Active Member

    Messages:
    2,592
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    90
    #7
    I guess I can't redirect something that does not exist now that I think of it :eek:
    I feel a bit dumb to think i could redirect the subdomain without even creating it lol.
    Thanks Jean-Luc!
     
    JasMate, Dec 31, 2007 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    Looks like the code was based on being located at domain.com, not blog.domain.com

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^blog.mydomain.com
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301]
     
    Nintendo, Dec 31, 2007 IP