Knowledge Base

How to redirect non-www to www with .htaccess on your site

For search engine optimization, you will need to choose only one version of your domain name to prevent duplicate content. That could be either www.example.com or the non-www version example.com

To redirect one to other, you will need to make sure Mod_Rewrite is enabled on your server. Edit your .htaccess file and add the code below. Note that in this case, the non-www version is redirected to the www version and you will need to replace your domain name below.

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

Was this helpful? Yes No

Still have questions?

If you still have questions, feel free to open a ticket and we will gladly help you out!

Open a ticket