www.webdeveloper.com
Results 1 to 2 of 2

Thread: Subdomains in .htaccess

  1. #1
    Join Date
    Oct 2003
    Posts
    215

    Subdomains in .htaccess

    I use .htaccess to add "www." to the front of the domain name if it is not present, via:

    Code:
    # Add a leading www to domain if one is missing.
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    How could I go about changing the rule so that it does not add the www. when a subdomain is being accessed, e.g. sub.domain.com

  2. #2
    Join Date
    Sep 2008
    Posts
    408
    I always do the opposite.

    Code:
    RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
    And that will only add to http://yourdomain.com/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles