Support: 1-800-961-4454
Sales Chat

Rackspace Cloudvent Calendar Day 10: Redirect HTTP To HTTPS On Your Cloud Load Balancer


In the spirit of the holiday season, I’m sharing some tips and features of our cloud that you may not know about. In this countdown I’ll have 24 posts for you, each covering a single topic or feature about Rackspace Cloud products. We’ll post one per day so keep checking back!

When I worked in support, customers would frequently ask me to create a redirect to HTTPS in their .htaccess files. For the record, here’s how to do that:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Rewrites using mod_rewrite on a web server is expensive from a processing perspective, as each request has to be evaluated to see if it should be redirected. If you want your entire site to be secure anyway, I recommend setting this up at the load balancer. Each request for HTTP will get a 301 redirect to the same resource but on HTTPS. Save the following JSON as lb.json, editing it with sane values for your scenario:

    "loadBalancer": {
        "name": "a-new-loadbalancer",
        "port": 443,
        "protocol": "HTTPS",
  "httpsRedirect": true
        "virtualIps": [
                "type": "PUBLIC"
        "nodes": [
                "address": "",
                "port": 80,
                "condition": "ENABLED"

Notice the httpsRedirect set to true? That’s where the magic happens. Now we just need to submit that JSON in a POST request to the Load Balancer API:

curl –s –X POST –d lb.json –H “Content-Type: application/json” –H “X-Auth-Token: $TOKEN”

Congrats! You’ve created a load balancer that will redirect insecure traffic to HTTPS.

Check back tomorrow for another tip! And be sure to take a look at the previous entries in the Rackspace Cloudvent Calendar.

About the Author

This is a post written and contributed by Hart Hoover.

Hart Hoover is a Cloud Strategist at Rackspace Hosting. Hoover started his career as a Racker in 2007 as a Linux Systems Administrator, providing technical support for dedicated servers. He moved to the cloud in 2009 to help design the Managed Cloud Servers support model. He has presented at various technical conferences, maintains and contributes to the Rackspace DevOps Blog, and advises Rackspace customers on best practices for cloud computing.

  • Vamsi Krishna

    Hi ! thanks for the article. where to save the lb.json file ?

  • Kris Law

    Your JSON appears to be missing a comma after the word true on this line:

    “httpsRedirect”: true

    Additionally, I get HTTP code 400: Invalid Response with the following error:

    {“messages”:[“JSON does not match the expected schema”]}

    Any ideas?

  • Christopher H. Laco

    For those who stumble on this post in the future, PyRax 1.6.4+ now has an option to tweak this using a simple python script as well:


Racker Powered
©2016 Rackspace, US Inc.