How can I test for HTTPS in a Rewrite Rule?

In order 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. 

This is an example rewrite rule 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]

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Generate a Certificate Signing Request - CSR in cPanel?

For obtaining a certificate from a Trusted SSL Provider, the Certificate Signing Request(CSR) is...

I have bought a secure certificate (SSL) with you, how do I know it has been installed correctly?

You need to visit your domain using "https://" at the start including the "www." part of your...

What is the set up procedure for an EV SSL Certificate?

When you first purchase an Extended Validation certificate, you will be contacted by GlobalSign...

Why does my SSL certificate not appear valid in old versions of Internet Explorer?

SSL certificates could only be set up on a one-per-IP address basis in the past. While this...

Why is my secure site not showing the padlock in the browser?

The main reason for this is the use of a http:// link to a graphic or script inside the site...