Redirect HTTP to HTTPS

If you need to force all traffic to the HTTPS of your website you will need to add the following to the a .htaccess file located in the folder where your website files are. If this is your main website for example: then these files are typically under the public_html folder. In the .htaccess file you need the following code to force HTTPS


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Force WWW

If you wish to force to have the www part in your URL at all times for example - instead of then you need the following code as well as the above in the .htaccess file: 

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Notes if you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already existing RewriteEngine On.

If you have any problems or need further assistance please raise a support ticket through the clients portal.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to install a Let's Encrypt SSL certificate in DirectAdmin

If you wish to install a free Let's Encrypt SSL certificate on your domain name that is hosted on...