While we have rules engine features for premium Verizon CDN endpoint, recently we have introduced rules engine feature for Microsoft CDN. While I am writing this blog, it’s in preview.
This blog explains how you can utilize this Rules engine feature in Microsoft Standard Azure CDN to redirect your request URL from http to https using PowerShell.
I assume that you already have an Azure CDN created with Microsoft Standard profile. If you don’t have one created already, follow this.
Ensure you have the Az.Cdn module installed on your machine. To check if the Az.CDN is installed or not, you can do the following,
installed and the module is successfully imported in the current session.
The following error while running Import-Module command means that you don’t have the Az.Cdn module installed yet. To install you have to run Install-Module -Name Az.Cdn -force command.
If you see the below error while running the install command then you need to run Install-Module -Name Az.Cdn -AllowClobber -Scope CurrentUser command to install it.
You may be prompted to confirm so that it can import this module for the first time.
PS command: Get-Module Az.Cdn
Make sure you use the latest version of Az.Cdn i.e. 1.3.0 so that you can use the new cmdlet which are released for setting the rules engine for a CDN endpoint.
Ensure that the above pre-requisites are followed before proceeding with the following steps.
Launch a new PowerShell session and run the following cmdlets:
#To connect to Azure account
#set the rule condition when the action will be performed
$RuleCondition = New-AzCdnDeliveryRuleCondition -MatchVariable 'RequestMethod' -Operator Equal -MatchValue "GET"
#Set the action what it should to once the condition is met, here we are doing http to https redirection
$RuleAction = New-AzCdnDeliveryRuleAction -RedirectType Moved -DestinationProtocol Https
#Set the Rule with condition and action we just created above
$Rule = New-AzCdnDeliveryRule -Name "rule1" -Order 1 -Condition $RuleCondition -Action $RuleAction
#Set the Azuer CDN delivery policy with the rule
$policy = New-AzCdnDeliveryPolicy -Description "RedirectPolicy" -Rule $Rule
#get the CDN endpoint reference
#please replace the below parameters as per the CDN endpoint details
$ep = Get-AzCdnEndpoint -ProfileName "<CDN Profile Name>" -EndpointName "<CDN Endpoint Name>" -ResourceGroupName "<Resource Group Name>"
#Assign the delivery policy to the CDN endpoint variable
$ep.DeliveryPolicy = $policy
#Now call the set CDN endpoint to save the changes on the CDN endpoint
Set-AzCdnEndpoint -CdnEndpoint $ep
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.