301 redirect question

Discussion in 'Search Engine Optimization' started by makeit easy, Jun 20, 2009.

  1. #1
    I want to redirect (301) all subdomains (including non-existing ones) to www.mydomain.com

    I couldn't find which command I should add to my htaccess.

    I can 301 redirect non-www to www. But that is not enough.
     
    makeit easy, Jun 20, 2009 IP
  2. siflur

    siflur Well-Known Member

    Messages:
    1,246
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    115
    #2
    siflur, Jun 20, 2009 IP
  3. Canonical

    Canonical Well-Known Member

    Messages:
    2,223
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    110
    #3
    First of all, you cannot redirect requests for non-existent subdomains because those requests will never make it to your server. Without a DNS entry for the non-existent domain, a browser will have no way of getting such a request to your web server. If the request never makes it to your server, you'll have no way of returning a 301.

    In regard to your existing subdomains, do you want to redirect requests for old URLs on the subdomains to the same page name on the www URL? For example, are you wanting to redirect

    http://subdomain1.example.com/folder/page1.html
    http://subdomain1.example.com/folder/
    http://subdomain1.example.com/

    to

    http://www.example.com/folder/page1.html
    http://www.example.com/folder/
    http://www.example.com/

    respectively? If so and the root folders for the subdomains are different from the root folder for the www domain then placing the following in the .htaccess files in the root of each of the subdomains should work:

    RewriteRule (.*) http://www.example.com/$1 [R=301,L]

    Or do you simply want to redirect the requests for URLs in the sub-domain to the root of the www domain? If so and the root folders for the subdomains are different from the root folder for the www domain then placing the following in the .htaccess files in the root of each of the subdomains should work:

    RewriteRule (.*) http://www.example.com/ [R=301,L]
     
    Canonical, Jun 20, 2009 IP
  4. sem-profiteer

    sem-profiteer Active Member

    Messages:
    257
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #4
    Just a note that the htaccess is very very sensitive. If you place a space in the wrong place you possible will shut down your entire site.
     
    sem-profiteer, Jun 20, 2009 IP
  5. siflur

    siflur Well-Known Member

    Messages:
    1,246
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    115
    #5
    I just tried to avoid making a link.
     
    siflur, Jun 20, 2009 IP
  6. makeit easy

    makeit easy Active Member

    Messages:
    2,067
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #6
    Sorry but this is not related to what I am asking. This is about how to redirect an internal page.

    I would like to know how I can redirect all possible subdomains to www.example.com

    For example; a.example.com, b.example.com, c.example.com, ..... are redirected to www.example.com






    Thanks for your reply. I know that I should add a wilcard (*) as an A record or CNAME to my name server.






    Any of the both options (folder to folder or folder to homepage) above is okay for me. However I prefer to redirect folders to folders. Because currently I have the command below on my htaccess:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
       RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Code (markup):
    So, the new additional command to redirect all subdomains to www.example.com/internalpage or www.example.com
    must not stop the function of already existing command above.
     
    makeit easy, Jun 21, 2009 IP