Problem with subdomain redirects

Discussion in 'Apache' started by solid7, Aug 29, 2006.

  1. #1
    I don't know if I'm doing this right or not, so please bear with me.

    I'm a big fan of deprecated URLs - specifically, no "www" addresses. So, I want to redirect all "www" requests to "non-www". That's pretty straightforward so far. I have easily done this using the following method:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.net$ [NC]
    RewriteRule ^(.*)$ http://mydomain.net/$1 [R=301,L]
    
    Code (markup):
    The problem is, this code is fine for the domain. But I cannot get it to work for the subdomains. So, my questions are as follows:

    A) do I need a .htaccess file in my subdomain, or can I make one top level to hit them all?
    B) why does this not work with subdomains? I tried putting the subdomain name in - i.e.; sudomain.mydomain.net - in the Rewrite.

    I don't know what I'm doing wrong here. I just want to redirect www to non-www for my domain, and ALL of its subdomains.

    Thank you.
     
    solid7, Aug 29, 2006 IP
  2. Brilliances

    Brilliances Active Member

    Messages:
    619
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I'm pretty new to mod_rewrites ... I wonder if this will work...

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^.*mydomain.net$
    RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]
     
    Brilliances, Aug 30, 2006 IP
  3. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Your .htaccess for the main domain is in the top web directory of the main domain.

    .htaccess files for a subdomain should be located in the top web directory of this subdomain.

    Jean-Luc
     
    Jean-Luc, Aug 30, 2006 IP
  4. solid7

    solid7 Well-Known Member

    Messages:
    459
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    148
    #4
    So then how do I redirect www to non-www on a subdomain?
     
    solid7, Aug 30, 2006 IP
  5. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I would try this :
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.subdomain\.mydomain\.net$ [NC]
    RewriteRule ^(.*)$ http://subdomain.mydomain.net/$1 [R=301,L]
    Code (markup):
    Jean-Luc
     
    Jean-Luc, Aug 30, 2006 IP
  6. WhatiFind

    WhatiFind offline

    Messages:
    1,789
    Likes Received:
    257
    Best Answers:
    0
    Trophy Points:
    180
    #6
    Looking for the same solution.

    I've set the top domain with the code from the first post. That works great!


    But now also looking for a solution for a subfolder.

    I want to redirect 301, from http://www.domain/sub/327.html to http://domain/sub/327.html

    Anyone has got a solution?
     
    WhatiFind, Aug 31, 2006 IP
  7. solid7

    solid7 Well-Known Member

    Messages:
    459
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    148
    #7
    Jean-Luc:

    That was the first thing that I tried, borrowing the logic from the top-level redirect. However, it produced a 404 error.

    ***edit*** I lied. Actually, it produced a server error. ("cannot find server", to be exact) Removing the .htaccess file clears up the problem, but is not a solution.
     
    solid7, Aug 31, 2006 IP