View Tutorial Metadata Edit Content Revision History Add to Watchlist Add New Tutorial Redirect from www to non www domain in Apache

Redirect from www to non www domain

For the search engines www.domain.com and domain.com are 2 different things. So usually, if you want to do some SEO on your website is better to choose one of those variants and redirect the other one to it using a 301 Redirect method ( to let the search engines know about this change ).

To do this you need to create a file called .htaccess, place it in the root of your server (if it does already exists don't overwrite it, just update it) and copy & paste the lines below :

a) from www.domain.com to domain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

b) from domain.com to www.domain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Only plain text supported.

Optional

Required - will be kept private

Optional

 
 

Rating: (1+, 0-) In: Apache