301 redirect everything from www. to non-www version

Discussion in 'Apache' started by kuser, May 31, 2012.

  1. #1
    I would like to 301 redirect everything from www.latinotimes.com to latinotimes.com
    can somebody tell me how to do this?
     
    kuser, May 31, 2012 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    You can create a .htaccess file inside the document root directory for your domain name with the following text:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www.latinotimes.com [NC]
    RewriteRule ^(.*)$ http://latinotimes.com/$1 [L,R=301]
     
    RoseHosting, May 31, 2012 IP
  3. jeffatrackaid

    jeffatrackaid Active Member

    Messages:
    168
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    75
    #3
    I prefer this approach:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
    Code (markup):
    This says that if the domain is NOT equal to example.com, then force it to be example.com. This will catch all alternate domains. The prior example will only rewrite www.example.com to example.com.
     
    jeffatrackaid, Jun 4, 2012 IP