NR Hosting Blog

SSL Detection on the Cloud

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:

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 ^(.*)$$1 [R=301,L]

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Show Buttons
Hide Buttons