By default your website can be accessed with both www.example.com and example.com. Since Google penalizes this due to duplicated content reasons, you should restrict the access to either www.example.com or example.com.
Example 1 – Redirect example.com to www.example.com:
If you want to redirect the site only in www.url then go to .htaccess and add following code.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
You should change www.example.com by your web address
Example 2 – Redirect www.example.com to example.com:
If you want to redirect the site only into the url without www. Then go to .htaccess and add following code.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]
Hits: 4
0
Leave a Comment