How to force HTTPS using the .htaccess file

Sometimes it's necessary to make sure your website’s visitors use the SSL encrypted connection. If you’re not familiar with SSL and would like to know more please review our article “What is SSL and Why is it important?” If you need assistance using the shared SSL that InMotion Hosting offers to shared hosting customers, please see our article on "forcing your visitors to use the shared ssl". Click here to learn more about Dedicated Hosting.

Forcing visitors to use SSL can be accomplished through your .htaccess file using mod_rewrite. If you’d like more information on mod_rewrite please read our article.

If you are using the Premium Website Builder and need to force your website traffic over SSL, please see the following article instead:
How to force your Premium Website Builder website over SSL

To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder. 

Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.

 

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

Be sure to replace www.example.com with your actual domain name.

To force a specific domain to use HTTPS, use the following lines of code 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 name you're trying force to https. Additionally, you need to replacewww.example.com with your actual domain name.

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific 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 actual folder name. Then be sure to replace www.example.com/folderwith your actual domain name and folder you want to force the SSL on.

  • 112 Users Found This Useful
Was this answer helpful?

Related Articles

How Do I Clear My Web Browser's Cache?

Each time you access a file through your web browser, it is cached (stored). In this way, certain...

How to Upload a File using the File Manager

You can upload your files directly through cPanel using the File Manager. File Manager is a web...

How to Find the URL of a File

If you want to share a web file with friends or the public, you first need to determine the...

Video tutorials not playing

In some cases our Video Tutorials are not playing or loading after displaying the SiveHost...

My Site is Slow

You have attempted to load your site and it appears to be running slow. Now what? We understand...