How do I force SSL using .htaccess
There are some ways to force SSL for your web site depending on your content. The subsequent tutorial shows one amongst the foremost common method to force SSL by using mod_rewrite in your .htaccess file.
Insert the code given below into the .htaccess go in the root folder of your web site to force all internet traffic to use HTTPS [SSL]. It’s vital that you just insert this above any pre-existing mod_rewrite code.
Note: Insert the code above any pre-existing mod_rewrite code.
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R,L]
If you would like to force only a particular domain to HTTPS use the subsequent code. Additionally, make sure to replace “example\.com” together with your “actual domain” name. The backslash
Note: The backslash “\” before the period is important.
RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R,L]
If you force SSL using these .htaccess rules and you finish up with an “endless redirection” or similar. it’s quite seemingly your script/software is attempting to re-direct back to non-ssl which is then being re-directed by .htaccess back to SSL. During this case, you’ll seemingly required to configure SSL usage in your script/software directly.