Skip to content
ADMAX
SEO and visibility

Force HTTPS and choose www or non-www

Since 1996Swedish supportServers in Sweden
Back to the knowledge base

The same website can be reached at several addresses: with and without https, and with and without www. To Google, these look like four separate websites with the same content. Choose one and redirect visitors and search engines there from the others.

First: enable SSL

Your website must have a valid certificate before you force https. See Add SSL to my web hosting. If you're using WordPress, also see WordPress and SSL.

In WordPress

  1. Log in to WordPress and go to Settings, then General.
  2. Update WordPress Address (URL) and Site Address (URL) to the address you've chosen, for example https://mycompany.com.
  3. Click Save Changes. You may need to log in again.

WordPress will then redirect visitors who arrive at the www or non-www version. To also redirect everyone to https, add the rule below to your .htaccess file.

In the .htaccess file

Open .htaccess in the public_html folder using the file manager in DirectAdmin (System Info & Files and File Manager). Add the rules at the top of the file, before # BEGIN WordPress.

Save a copy of .htaccess before making any changes. A typo can cause your entire website to show an error.

Https and without www:

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

Https and with www:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]

Check the result

Enter all four variants in your browser, for example http://mycompany.com and http://www.mycompany.com. All of them should end up at the same address. If you get a "too many redirects" error, there are two rules conflicting with each other. Remove the new rule and check your WordPress settings.

Use the same variant in Google Search Console, in links on the website, and in your sitemap.

Https and www in other publishing tools

Joomla

  1. Check that the file htaccess.txt in public_html has been renamed to .htaccess. Without this, neither clean URLs nor the rules above will work.
  2. Go to System and Global Configuration, the Server tab.
  3. Set Force HTTPS to Entire Site and save.
  4. Add the www or non-www rule to .htaccess as described above, directly after the existing RewriteEngine On line in Joomla's file.

Drupal

  1. Open .htaccess in your website's root folder.
  2. Drupal's file includes ready-made, commented-out lines for adding or removing www. Remove the # character from the two lines that suit your needs.
  3. Add the https rule as described above.
  4. If present, update the trusted_host_patterns setting in settings.php to allow the address you've chosen.

Wix, Squarespace and Shopify

Https is handled automatically. You choose which address is the primary one, with or without www, in the domain settings. The other variant is then redirected accordingly.

Wix, Squarespace and Shopify run on their respective providers' own servers, not on your web hosting. Menu names can change from time to time, so search their help centres if you can't find the setting.

Menus in Joomla and Drupal are usually the same in English as in Swedish. If your control panel looks different, it may be due to the version you're running.