Force HTTPS using .htaccess

If you have a SSL certificate installed on your domain and you would like to force your website visitors over to your SSL (HTTPS) to secure connections to your site, you can use the following code in your .htaccess file (Linux).

This will force all visitors to your website via the secure URL over https. Be sure to replace example.com with your actual domain name. If you do not wish for the www. to be included, remove the www. from the .htaccess rules below.

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

If you want to force a specific domain, you can use the following. Be sure to replace example.com with your actual domain name.

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

Finally, if you want to force just a folder over to https, you can use the following rewrite rule. Be sure to replace example.com with your actual domain name.

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

If you have any issues, please don't hesitate to contact us and we'll be glad to assist.

Looking for reliable Linux hosting with Award Winning Customer Support?
Grab your hosting today with a 20% discount. All plans come with our 60 Money Back Guarantee!

Check out our plans & promotions on our website -- https://www.peopleshost.com/

  • rewrite, https, SSL, redirect, htaccess, .htaccess
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Do I need a SSL certificate?

Do I really need an SSL certificate? Historically,  your website would only need an SSL...

Common types of SSL certificates

While there are many different types of SSL certificates, we'll cover the main three PAID...

Shared SSL Certificates

Unfortunately, we do not offer any shared SSL certificates on either or Linux or Windows shared...

How to buy an SSL certificate

You can purchase an SSL certificate automatically via your secure billing portal here --...

Self Signed SSL Certificate

If you are a developer, webmaster or site owner and you need to test SSL functionality on your...