KNOWLEDGEBASE



How to force HTTPS using the .htaccess file

There is a big push to secure the web and islandhosting.com supports both http and https by default using Let's Encrypt free SSL.

To force all web requests to use HTTPS add following in the .htaccess file in your website’s root folder. 

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Be sure to replace www.example.com with the domain name.

To force a specific domain to use HTTPS, use the following in the .htaccess file in your website's root folder:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Make sure to replace example\.com with the domain you're trying force to https.
Additionally, you need to replace www.example.com with your domain.

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that folder:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} folder 
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]

Make sure you change the folder reference to the name of the folder.
Then be sure to replace www.example.com/folder with your domain name and folder.

 


Also Read

What PHP Versions Islandhosting.com supports and how to set them.
Can I get a domain and host it elsewhere?
Increasing, or decreasing your upload_max_filesize in php settings.
DDoS Protection
SSH Access