rewrites & subdomains

Discussion in 'Apache' started by Solicitors Mortgages, Mar 8, 2006.

  1. #1
    I have my site 301'ed from the non-www version to the www, how can I then stop www being added to the front of my subdomains? :confused:

    TIA...........

    James
     
    Solicitors Mortgages, Mar 8, 2006 IP
  2. Slapyo

    Slapyo Well-Known Member

    Messages:
    266
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    You can combine the two. You should be able to put the code to force the www. in .htaccess in your domain root. Then put the code to strip the www. in a .htaccess in your subdomain root folder. You will have multiple .htaccess files.

    The following code will always add the www to the URL.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Code (markup):
    The following code will remove the www from every URL.
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+)$
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    Code (markup):
     
    Slapyo, Mar 15, 2006 IP