We are in the process of setting up a static custom domain website with SSL being hosted from an Azure storage account.
After getting HTTPS protocol to work, it is necessary to set up HTTP Rules for the CDN endpoint to be able to serve up the proper landing page of the website, plus force redirecting of all http traffic to https.
Previous steps in Setting up a custom domain website being hosted from an Azure storage account:
- Hosting a Static Website from an Azure Storage Account
- How to Add a Custom Domain to an Azure Storage Account
- Create an Azure CDN
- Add an Azure Content Delivery Network Endpoint
- Migrate a custom domain name to the CDN endpoint
In order to be able to configure the Azure CDN’s Rules Engine, the Azure CDN Profile must be the Premium Verizon pricing tier. This is the only one of the 4 Azure CDN products that have the Rule Engine feature:
The Azure CDN Rules Engines allows customization of how HTTP requests are handled.
Azure portal > CDN Profile > Manage > HTTP Large > Rules Engine
These are the rules added to the CDN for all endpoints on the CDN profile, since all endpoints are static websites. The order of rules is important, as the Rules Engine applies rules from the top rule down.
Rules can be added globally to all CDN endpoints or to individual endpoints of the container as seen in the Source drop down options. This is a screen shot of a Rule Source of a CDN profile containing endpoints to 3 custom domains :
Rule 1: Redirect HTTP to HTTPS
1 2 3 4 5 6 7 8 |
match condition: if Request Scheme = HTTP feature: URL Redirect - Code: 301, Source: (choose individual or global endpoint ) Source Pattern: (.*), Destination: https://{host}/$1 |
Rule 2: Redirect Root to www
1 2 3 4 5 6 7 8 9 |
match condition IF Edge Cname <yourRootDomainName> feature: URL Redirect - Code 301, Source (choose individual or global endpoint) Source Pattern: (.*) Destination: https://<yoursubdomain>/$1 |
Rule 3: HSTS Header
1 2 3 4 5 6 7 |
match condition IF Always feature: Modify Client Response Header - Append, Name: Strict-Transport-Security, Value: max-age=31536000 |
Rule 4: URL Rewrite (x2)
1 2 3 4 5 6 7 8 9 10 11 |
match condition IF Always feature (make 2 features with +) URL Rewrite, Source: (choose individual or global endpoint) Source Pattern: ((?:[^\?]*/)?)($|\?.*) Destination: (choose individual or global endpoint) Destination Pattern: $1index.html$2 URL Rewrite, Source: (choose individual or global endpoint) Source Pattern: ((?:[^\?]*/)?[^\?/.]+)($|\?.*) Destination: (choose individual or global endpoint) Destination Pattern: $1/index.html$2 |
Resources:
- Azure CDN rules engine reference
- Azure CDN rules engine match conditions
- Override HTTP behavior using the Azure CDN rules engine
- Azure CDN rules engine features