How do I force SSL using .htaccess?

Forcing SSL for your site can be accomplished numerous ways depending on your content but one of the most common is by using mod_rewrite within your .htaccess file.

To force all web traffic to use HTTPS [SSL] you can insert the following lines of code into the .htaccess file in the root folder of your website.  It is important that you insert this above any pre-existing mod_rewrite code.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Should you wish to only force a specific domain to HTTPS you would use the following code - making sure to replace "example\.com" with your actual domain name.  The back slash "\" before the period is important.
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
If you force SSL using these .htaccess rules and you end up with an "endless redirection" or similar it is quite likely your script/software is trying to re-direct back to non-ssl which is then being re-directed by .htaccess back to SSL.  In this case you will likely need to configure SSL usage within your script/software directly.
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

How do I modify the nameservers of my domain name?

If your domain name is registered with us, you can modify its name servers by following the...

How to lock/unlock my domains?

To lock/unlock your domain registered with us you need to: 1. Log into domain section in client...

How to register my private nameservers?

To register private namesevers for your domain registered with us: 1. Log into domain section in...

How to renew a domain name?

To renew your domain registered with us do the following: 1. Log into domain section in client...

How to transfer my domain name?

Before you transfer your domain name, there are a few requirements: 1. The domain name must be...