Tsohost Knowledge Base

SSL Detection on the Cloud

Modified Monday 5th September, 2016 at 06:32

Was this helpful?

To facilitate SSL functionality across multiple web servers in a clustered environment we deploy a separate SSL load balancer. This means that sites can have SSL enabled with no downtime due to the IP change.

If you are developing an application to run on your clustered hosting account, you may wish to detect whether or not the user is accessing your site over SSL and to redirect them appropriately.

PHP-Based Sites on the Cloud

For PHP you should use the variable $_SERVER['HTTP_X_FORWARDED_PROTO'] which will be set to 'HTTPS' when the user is accessing over SSL (https://yoursite/) and will be unset when the user is not.  Some applications require the $_SERVER['HTTPS'] and $_SERVER['SERVER_PORT'] variables to be set to "on" and "443" respectively when the user is accessing over SSL.  This can be done with the following code in the configuration file of your website: 

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}

Windows Sites on the Cloud

Under ASP .NET (C#) you are looking for HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_PROTO"] which will be set to 'HTTPS' if the user is accessing over SSL and will be null if the user is not.

Under classic ASP it's Request.ServerVariables("HTTP_X_FORWARDED_PROTO").

If you wanted to force SSL with a .htaccess rewrite, the rule would look like this:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://exampledomain.com/$1 [R=301,L]

Please bear in mind you need to change yourdomain.com with your actual domain name.

Still can't find what you're looking for?

Not a problem - our 24/7 customer support team are super friendly and here to help answer all your questions. There's no need to wait, click below to start a Live Chat.

Start Live Chat

Still can't find what you're looking for?

Not a problem - our 24/7 customer support team are super friendly and here to help answer all your questions. Don't delay, click below to find out how you can get in touch.

Get in Touch