Version Française

.htaccess: URL without "www"

Written by David Grégoire | 8 December 2009

Some people say you shouldn't have two different URLs pointing to exactly the same place, without redirection.

However, it's an esthetic choice to show, or not, the "www" in front of the domain name. So, if you prefer not having the "www", use:


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

If you rather prefer having the "www", use:

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

Note that your Apache server should have MOD_REWRITE enabled.

Tags: htaccess, http_host, MOD_REWRITE, rewriteCond, rewriteRule, seo, url, www,

Category: Free stuff

Address of this article : http://sparko.ca/10

Share:

Comments


Merab on 26 April 2012 13:05
You might need to put some rules for the images or js files that use the maacientnne.html file.Also, since RewriteCond expects a regular expression, you need to escape the dot (!^/maacientnne.html$)Regards!

Write a comment

Your message 17 + 9 = ?