How to setup redirect rules in Azure CDN

Recently, I was working on a project where we moved AWS CloudFront to Azure CDN. In the CloudFront configuration, Behaviours were configured to pull the content from two S3 buckets. Also, Two CNAME records were attached to single Distribution. For example, If the requested URL contains a specific path (/images/babies/) then it should pull content from S3 bucket Images and for anything else it should pull content from other S3 bucket Default. Azure CDN can have more than one Custom hostname, but can have only one origin. Multiple origins are not supported.

After digging here and there we found that Azure CDN Premium can do redirection based on the given condition which can do a similar job what AWS CloudFront is doing.

Here are the steps we need to perform the achieve the same in Azure CDN:

  • Create Azure CDN Profile with Premium Verizon and a CDN endpoint

azure cdn

  • We will create one more CDN Endpoint to where we will redirect the request based on the given condition.
  • Once the deployment is done, go to Azure CDN Profile and click on Manage button. It will redirect to CDN Console where we will set up the Rule.

azure cdn profile

  • On the CDN Console, Go to HTTP Large menu and select Rules Engine.

azure cdn

  • Now we will create a rule which redirects the request if the request contains/images/babies/ in it.
  • Below the snapshot of the rule, I configured. Once, you add the rule, it might take up to 4hrs to become active.

azure cdn redirect rule

  • Now let’s do the test

azure cdn

Look at Request URL and URL in the Address bar. Azure CDN redirected the request to a different endpoint based on the rule.

I hope this article will help you in case you face a similar situation. Please leave a comment if I missed something or you want to add something.

Thanks to Microsoft and Verizon who helped me here to set up this rule. Microsoft also said that adding more than one more Origins in Azure CDN Endpoint is in the roadmap. Hopefully, they will release this feature soon so we don’t have to do the redirection. Also, Azure CDN Premium costs 2x compared to Standard.

2 Replies to “How to setup redirect rules in Azure CDN”

Leave a Reply