Contents

Redirect HTTP traffic to HTTPS in Azure CDN

Contents

One of my little projects is a static website running on Azure CDN, with a custom domain endpoint enforcing HTTPS traffic only. This caused a little issue when attempting to reach the URL via http, as my sister-in-law kept doing.

/media/2021/03/image.png

Now when I set this up, I assumed that any HTTP requests would redirect to the HTTPS equivalent. Obviously, I was wrong.

Azure CDN has a rules engine that allows you to redirect traffic, this can be used to replace all HTTP traffic to HTTPS.

  • Navigate to the CDN endpoint and on the left-hand navigation select Rules Engine, then create a new rule.
  • Add a condition where the Request Protocol is HTTP.
  • Add a URL Redirect action and set the Type to 302 and the Protocol to HTTPS, leaving all the other fields blank. By leaving these other fields blank it maintains the URL path and any query parameters, only the protocol will change.

/media/2021/03/image-1.png

Once saved, it can take up to 10 minutes to propagate to all the CDN Points of Presence. But then any HTTP traffic should redirect successfully.