Force SSL/https using .htaccess

In order to redirect your website to be opened through HTTPS, you should add the following rewrite rule in your.htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.domain.com/%{REQUEST_URI} [R,L]

This will redirect your domain to https://www.yourdomain.com.

If you wish the redirect to work without www, you should remove it from the rewrite rule:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://domain.com/%{REQUEST_URI} [R,L]

Was this answer helpful?

 Print this Article

Also Read

How to protect your account from TRACE request attacks?

In order to protect your account from HTTP TRACE request attacks, you can add this to your...

How to block access to a specific folder?

To block all access to a specific folder in your account, you should add this rule to the...

How Do Websites Get Hacked?

The most common reasons for a hacked (defaced) website include: Outdated web application....

What is a Brute Force Attack and how to block it

Brute Force is a method of guessing your password by trying combinations of letters, numbers and...

How to clean malicious code from your website?

If your website has been hacked and malicious content has been inserted into your files, you...