htaccess

We all had this problem redirecting non-www to www but it’s really easy to fix it with a few lines of codes.

Just add the code below into your .htaccess file and don’t forget to replace yoursite.com with your domain name.

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

 

Or the code below will work on any websites.

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

 

Important: add RewriteEngine On at the top of your .htaccess if you don’t have it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here