htaccess - with www. or without www.

That's always the question! If the user enters 'domain.com' is this to be redirected to www.domain.com or else if the user enters 'www.domain.com' has to be redirected to 'domain.com' instead - one scenario is a MUST to choose!

Why? First, and most important - because of SEO reasons, gOOgle treats 'no-scenario' as a duplicate content, unlike one and the very same page, therfore it gives less rank points. According to gOOgle: The same content should never be available under two different URLs. Second, it's good to standarize, look.. it was always the problem, how many times did you hear somebody asking "..With or without www?"

So, enough! Time to choose:

Simply you have to paste selected scenario code into the .htaccess file:

Rewrite "www.example.com -> example.com"

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
{/ IfModule>

Rewrite "example.com -> www.example.com"

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
{/IfModule>

 

Be sure to check if you have already started the RewriteEngine or not.

If not, put in first this code:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# RewriteBase /
{/IfModule>

 

That's it.
Try to access your webpage, both with www. and without it and see the effect.