Tsohost Help Centre

Table of Contents

SSL Detection on the Cloud

Updated Oct 31st, 2017 at 12:13 GMT

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';

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.