Knowledge Base

How to redirect www to non-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 www version is redirected to non-www and you will need to replace your domain name below.

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

If you already have a .htaccess file with RewriteEngine On copy only the following code after that line.

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

Was this helpful? 😃 😞

Still have questions?

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

Open a ticket