Home » Categories » Add-Ons » SSL Certificates

How can I test for HTTPS in a Rewrite Rule?

To test if a connection is being made using SSL encryption, you need to use the HTTPS environment variable.

This will either be “On” if the request is made over HTTPS or it will be undefined if it is made over HTTP.

Other methods to test for HTTPS may fail on our server architecture.

Here is an example rewrite rule you can add to your .htaccess file that will redirect all requests made over HTTP to the HTTPS URL:

RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

2.53 (17)
Article Rating (17 Votes)
Rate this article
  • Icon PDFExport to PDF
Related Articles
What is a Wildcard SSL certificate?
Added on Wed, Dec 2, 2020
Resolve an INVALIDDOMAIN error
Added on Wed, Dec 2, 2020
How does an SSL certificate work?
Added on Wed, Dec 2, 2020