How to force www or non-www versions of your website using .htaccess rules

To force your website to use either “www” or “non-www” versions, simply use the code below in your .htaccess file in the public_html root OR the location of your websites main files. You may need to create the .htaccess file (AKA dot htaccess)

To force www:

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

To force non-www:

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

Note: If you have a CMS such as WordPress or Joomla, you will need to ensure your website settings from your dashboard reflects the above rules that you use.

  • Email, SSL
  • 0 Χρήστες που βρήκαν αυτό χρήσιμο
Ήταν χρήσιμη αυτήν την απάντηση;

Related Articles

How do I upload files to my website?

You must either use FTP (file transfer protocol) client, or upload via our File Manager located...

I don't know what is FTP. Do you have some File Manager?

If you do not wish to use an FTP (file transfer protocol) client, you may use our file manager...

Where can I find my FTP information?

To find your FTP details, please log on to your control panel, click the 'View FTP Details' link...

Search engine friendly (virtual) URLs not working!

We use virtual user home directory paths so you can get errors when trying to setup search engine...

My website shows "Internal Server Error"

There are many different possibilities. And in most cases it is due incorrect .htaccess file...