Naked domain to www redirection .htaccess code

I know, that many struggles in avoiding the duplications of your web contents through www.domain and just domain.

Basically, search engines consider www.domain & domain as 2 separate websites.so, your contents will be considered as duplicate contents, the value of your web contents will be reduced.

You can avoid this by using  .htaccess code on the root folder of the website
This .htaccess codes using the apache mod_rewrite module.

Naked domain to www redirection .htaccess code

RewriteEngine On

### Naked domain to www redirection

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

### Naked domain to www redirection with https
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

do, give us your feedback on the results.

Consider Looking at our other posts on Hosting & Linux

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.