Home htaccess Redirect non-www to www in .htaccess
Redirect non-www to www in .htaccess

Redirect non-www to www in .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.


Related posts

Write a comment

Sign up for our newsletters.

Do you want to see our new posts?

Enter your email below to get our latest posts! (NO SPAM!)