How to Force SSL with .htaccess

Even if you have installed an SSL certificate, your website will still be accessible via HTTP. To completely secure your website, use the .htaccess file to force an HTTPS connection. This activity requires the addition of new code to the file.

Forcing Universal HTTPS

  • Step 1. Log in to your web hosting control panel
  • Step 2. Find the .htaccess file and open it for editing. You can typically find the file in the root directory of your public_html folder. If the file does not exist, create a blank text file and later save it as .htaccess.
  • Step 3. Add the following code –

RewriteEngine On

RewriteCond %{HTTPS} off

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

  • Step 4. Save the changes before exiting the file.

The steps above will enforce HTTPS for all web traffic to the site. You can also specify if you wish to force HTTPS to a specific domain or even a particular folder.

Forcing HTTPS for a Specific Domain

If your account handles multiple websites, you may, on occasion, wish to enforce HTTPS for specific sites. If so, add the following code instead:

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

Replace “” with the domain name for which you wish to force HTTPS.

Forcing HTTPS on a Specific Folder

Aside from entire domain names, the .htaccess file can also force HTTPS for specific folder content only. If this is the case, add the following code:

  • RewriteEngine On 
  • RewriteCond %{REQUEST_URI} folder
  • RewriteRule ^(.*)$$1 [R,L]

Replace “folder” with the name of the folder for which you want to force HTTPS. Replace with the domain name to which the folder belongs.

Was this helpful?

What’s your goal today?

1. Find the right Web hosting solution

If you’re looking for industry-leading speed, ease of use and reliability Try ScalaHosting with an unconditional money-back guarantee.

2. Make your website lighting fast

We guarantee to make your WordPress site load in less than 2 seconds on a managed VPS with ScalaHosting or give your money back. Fill out the form, and we’ll be in touch.

Please enter a valid name
Please enter a valid website
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

3. Streamline your clients’ hosting experience

If you’re a web studio or development agency hosting more than 30 websites, schedule a call with Vlad, our co-founder and CTO, and see how we can deliver unmatched value to both your business and your clients.


Need a custom cluster or professional advice?

Book a meeting and get a free 30-minute consultation with Vlad, co-founder & CTO of Scala Hosting, who will help you select, design and build the right solution - from a single data center cluster to a multi-region & multi-datacenter high availability cluster with hundreds of servers.

Book a free consultation

4. Learn how to grow your website in 2024

An all-star team of SEO and web influencers are sharing their secret knowledge for the first time in years. Learn about the future of SEO, Web Design best practices and the secrets to getting the foundation for your website to thrive. Watch the exclusive webinar.

An Exclusive Insiders Look Behind The SEO and Web Development Curtain


Working in the web hosting industry for over 13 years, Rado has inevitably got some insight into the industry. A digital marketer by education, Rado is always putting himself in the client's shoes, trying to see what's best for THEM first. A man of the fine detail, you can often find him spending 10+ minutes wondering over a missing comma or slightly skewed design.