.htaccess code without www version of website. Help please.

Discussion in 'Apache' started by JEET, Jan 22, 2010.

  1. #1
    Hi,
    Below is my .htaccess code. It works perfectly (redirects website visitors from www version of my site to the non-www version of website)

    However, I need to change the domain name for all websites I setup and was hoping if someone could post or modify the code so it works with any domain where the .htaccess file is present (and I don't need to modify the .htaccess file for each domain). In the below code "domain.com" is the domain name.

    
    RewriteCond %{HTTP_HOST} !^domain\.com$
    RewriteRule (.*) http://domain.com/$1 [R=301,L]
    
    
    Code (markup):
    Thanks :)
     
    JEET, Jan 22, 2010 IP
  2. Yatko

    Yatko Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    # require www prefix for all urls of ANY domain & for parked domains by Yatko.com
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.               [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+\.[a-z]{2,6})$ [NC]
    RewriteRule ^(.*)$       http://www.%1/$1      [R=301,L]
    
    Code (markup):
     
    Yatko, Jul 17, 2010 IP