Home
%3CLINGO-SUB%20id%3D%22lingo-sub-797076%22%20slang%3D%22en-US%22%3EAzure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-797076%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%3CU%3EUse%20Case%3A%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWhile%20we%20have%20rules%20engine%20features%20for%20premium%20Verizon%20CDN%20endpoint%2C%20recently%20we%20have%20introduced%20rules%20engine%20feature%20for%20Microsoft%20CDN.%20While%20I%20am%20writing%20this%20blog%2C%20it%E2%80%99s%20in%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-in%2Fupdates%2Frules-engine-for-azure-content-delivery-network-is-now-in-preview%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epreview%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EThis%20blog%20explains%20how%20you%20can%20utilize%20this%20Rules%20engine%20feature%20in%20Microsoft%20Standard%20Azure%20CDN%20to%20redirect%20your%20request%20URL%20from%20http%20to%20https%20using%20PowerShell.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EPre-requisites%3A%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EI%20assume%20that%20you%20already%20have%20an%20Azure%20CDN%20created%20with%20Microsoft%20Standard%20profile.%20If%20you%20don%E2%80%99t%20have%20one%20created%20already%2C%20follow%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcdn%2Fcdn-create-new-endpoint%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3EEnsure%20you%20have%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.cdn%2F%3Fview%3Dazps-2.5.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSTRONG%3EAz.Cdn%3C%2FSTRONG%3E%3C%2FA%3Emodule%20installed%20on%20your%20machine.%20To%20check%20if%20the%20Az.CDN%20is%20installed%20or%20not%2C%20you%20can%20do%20the%20following%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOpen%20PowerShell%20as%20%3CSTRONG%3EAdministrator%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ERun%20command%20%3CSTRONG%3EImport-Module%20Az.Cdn%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20the%20above%20command%20doesn%E2%80%99t%20throw%20any%20error%2C%20you%20have%20the%20Az.Cdn%20PowerShell%20module%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3Einstalled%20and%20the%20module%20is%20successfully%20imported%20in%20the%20current%20session.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EThe%20following%20error%20while%20running%20%3CSTRONG%3EImport-Module%3C%2FSTRONG%3Ecommand%20means%20that%20you%20don%E2%80%99t%20have%20the%20Az.Cdn%20module%20installed%20yet.%20To%20install%20you%20have%20to%20run%20%3CSTRONG%3EInstall-Module%20-Name%20Az.Cdn%20-force%3C%2FSTRONG%3Ecommand.%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126370i2FB8401B1E60753B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22first.jpg%22%20title%3D%22first.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EIf%20you%20see%20the%20below%20error%20while%20running%20the%20install%20command%20then%20you%20need%20to%20run%20%3CSTRONG%3EInstall-Module%20-Name%20Az.Cdn%20-AllowClobber%20-Scope%20CurrentUser%20%3C%2FSTRONG%3Ecommand%20to%20install%20it.%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20950px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126371iCDBE3E98CE2BE192%2Fimage-dimensions%2F950x152%3Fv%3D1.0%22%20width%3D%22950%22%20height%3D%22152%22%20alt%3D%222.jpg%22%20title%3D%222.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENow%20to%20check%20if%20the%20Az.Cdn%20module%20is%20installed%20successfully%2C%20you%20can%20try%20importing%20the%20module%20using%20the%20command%3A%20%3CSTRONG%3EImport-Module%20Az.Cdn%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EYou%20may%20be%20prompted%20to%20confirm%20so%20that%20it%20can%20import%20this%20module%20for%20the%20first%20time.%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126372i72C4A250B80EE7CD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%223.jpg%22%20title%3D%223.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_3%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CUL%3E%0A%3CLI%3EYou%20can%20also%20run%20%3CSTRONG%3EGet-Module%3C%2FSTRONG%3Ecommand%20to%20confirm%20if%20it%E2%80%99s%20imported%20successfully%20in%20your%20PowerShell%20session%20and%20what%20version%20it%E2%80%99s%20currently%20using%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EPS%20command%3A%20%3CSTRONG%3EGet-Module%20Az.Cdn%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126373iAA6FF199E197B9A4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%224.jpg%22%20title%3D%224.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_4%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EMake%20sure%20you%20use%20the%20latest%20version%20of%20Az.Cdn%20i.e.%201.3.0%20so%20that%20you%20can%20use%20the%20new%20cmdlet%20which%20are%20released%20for%20setting%20the%20rules%20engine%20for%20a%20CDN%20endpoint.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ESteps%3A%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EEnsure%20that%20the%20above%20pre-requisites%20are%20followed%20before%20proceeding%20with%20the%20following%20steps.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELaunch%20a%20new%20PowerShell%20session%20and%20run%20the%20following%20cmdlets%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23To%20connect%20to%20Azure%20account%3C%2FP%3E%0A%3CP%3EConnect-AzAccount%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23set%20the%20rule%20condition%20when%20the%20action%20will%20be%20performed%3C%2FP%3E%0A%3CP%3E%24RuleCondition%20%3D%20New-AzCdnDeliveryRuleCondition%20-MatchVariable%20'RequestMethod'%20-Operator%20Equal%20-MatchValue%20%22GET%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23Set%20the%20action%20what%20it%20should%20to%20once%20the%20condition%20is%20met%2C%20here%20we%20are%20doing%20http%20to%20https%20redirection%3C%2FP%3E%0A%3CP%3E%24RuleAction%20%3D%20New-AzCdnDeliveryRuleAction%20-RedirectType%20Moved%20-DestinationProtocol%20Https%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23Set%20the%20Rule%20with%20condition%20and%20action%20we%20just%20created%20above%3C%2FP%3E%0A%3CP%3E%24Rule%20%3D%20New-AzCdnDeliveryRule%20-Name%20%22rule1%22%20-Order%201%20-Condition%20%24RuleCondition%20-Action%20%24RuleAction%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23Set%20the%20Azuer%20CDN%20delivery%20policy%20with%20the%20rule%3C%2FP%3E%0A%3CP%3E%24policy%20%3D%20New-AzCdnDeliveryPolicy%20-Description%20%22RedirectPolicy%22%20-Rule%20%24Rule%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23get%20the%20CDN%20endpoint%20reference%3C%2FP%3E%0A%3CP%3E%23please%20replace%20the%20below%20parameters%20as%20per%20the%20CDN%20endpoint%20details%3C%2FP%3E%0A%3CP%3E%24ep%20%3D%20Get-AzCdnEndpoint%20-ProfileName%20%22%3CCDN%20profile%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20name%3D%22%22%3E%22%20-EndpointName%20%22%3CCDN%20endpoint%3D%22%22%20name%3D%22%22%3E%22%20-ResourceGroupName%20%22%3CRESOURCE%20group%3D%22%22%20name%3D%22%22%3E%22%3C%2FRESOURCE%3E%3C%2FCDN%3E%3C%2FCDN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23Assign%20the%20delivery%20policy%20to%20the%20CDN%20endpoint%20variable%3C%2FP%3E%0A%3CP%3E%24ep.DeliveryPolicy%20%3D%20%24policy%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23Now%20call%20the%20set%20CDN%20endpoint%20to%20save%20the%20changes%20on%20the%20CDN%20endpoint%3C%2FP%3E%0A%3CP%3ESet-AzCdnEndpoint%20-CdnEndpoint%20%24ep%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-797076%22%20slang%3D%22en-US%22%3E%3CP%3EConfigure%26nbsp%3B%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3ERules%20Engine%20for%20http%20to%20https%20redirection%3C%2FFONT%3Efor%20Microsoft%20Standard%20CDN%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-797076%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20CDN%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20CDN%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819360%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819360%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%20This%20document%20has%20helped%20me%20a%20lot.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%2C%20is%20there%20a%20way%20to%20remove%20the%20policy%20that%20has%20been%20attached.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-828683%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-828683%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397182%22%20target%3D%22_blank%22%3E%40varadasandeep%3C%2FA%3Eyou're%20welcome.%3C%2FP%3E%0A%3CP%3ETo%20remove%20the%20policy%20from%20an%20endpoint%2C%20you%20can%20do%20a%20Get-AzCdnEndpoint%20to%20retrieve%20endpoint%20data.%20Once%20you%20get%20the%20endpoint%20data%2C%20set%20its%20deliveryPolicy%20to%20null%2C%20then%20do%20another%20Update-AzCdnEndpoint%20with%20the%20updated%20endpoint%20data.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-855071%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-855071%22%20slang%3D%22en-US%22%3E%3CP%3EHello!%26nbsp%3B%20We%20keep%20getting%20the%20following%20error%20when%20trying%20to%20run%20the%20Set-AzCdnEndpoint%20cmdlet%20for%20a%20Standard%20Microsoft%20CDN%20Profile.%26nbsp%3B%20Tested%20on%20Az.Cdn%201.3.0%2C%201.3.3%2C%20and%20current%20Cloud%20Shell.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESet-AzCdnEndpoint%20%3A%20Operation%20returned%20an%20invalid%20status%20code%20'BadRequest'%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20the%20following%20in%20the%20400%20response%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%22message%22%3A%20%22A%20type%20named%20'Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRedirectActionParameters'%20could%20not%20be%20resolved%20by%20the%20model.%20When%20a%20model%20is%20available%2C%20each%20type%20name%20must%20resolve%20to%20a%20valid%20type.%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAre%20you%20able%20to%20reproduce%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-858411%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858411%22%20slang%3D%22en-US%22%3ESame%20as%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F408726%22%20target%3D%22_blank%22%3E%40jcrosbyrwb%3C%2FA%3E%20here.%20BadRequest%20on%20Set-AzCdnEndpoint%20with%20As.Cdn%201.3.1%20Any%20help%20about%20this%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-858466%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-858466%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F408726%22%20target%3D%22_blank%22%3E%40jcrosbyrwb%3C%2FA%3E%20%26amp%3B%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F410162%22%20target%3D%22_blank%22%3E%40technetColmar%3C%2FA%3E%20%2C%3C%2FP%3E%0A%3CP%3EI'm%20able%20to%20reproduce%20this%20error%2C%20seems%20like%20something%20has%20changed%2C%20I'm%20checking%20more%20on%20this%20internally%2C%20will%20post%20further%20updates%20on%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-872121%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-872121%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F410162%22%20target%3D%22_blank%22%3E%40technetColmar%3C%2FA%3E%20%26amp%3B%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F408726%22%20target%3D%22_blank%22%3E%40jcrosbyrwb%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3EThere%20was%20a%20fix%20planned%20to%20release%20for%20this%20issue%20in%20next%202-3%20weeks%2C%20you%20can%20expect%20this%20to%20work%20by%20then.%20I'll%20update%20this%20thread%20once%20the%20fix%20is%20deployed%20for%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-872237%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-872237%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F380788%22%20target%3D%22_blank%22%3E%40Braja%3C%2FA%3E!%26nbsp%3B%20We're%20holding%20up%20a%20production%20rollout%20of%20a%20site%2C%20so%20this%20fix%20will%20be%20much%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-898176%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-898176%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20seems%20to%20have%20been%20resolved%20now.%20I%20just%20completed%20the%20steps%20without%20error%20today.%20However%2C%20this%20then%20resulted%20in%20an%20infinite%20redirect%20as%20it%20seemed%20to%20be%20matching%20HTTPS%20as%20well%20as%20HTTP.%20Given%20that%20the%20rule%20only%20matches%20GET%20verbs%20and%20ignores%20the%20scheme%2C%20I%20guess%20this%20was%20to%20be%20expected.%20I%20tried%20to%20guess%20how%20to%20add%20another%20condition%3A%3C%2FP%3E%3CPRE%3E%24protocolCondition%20%3D%20New-AzCdnDeliveryRuleCondition%20-MatchVariable%20'RequestScheme'%20-Operator%20Equal%20-MatchValue%20%22HTTP%22%0A%24ep.DeliveryPolicy%5B0%5D.Rules%5B0%5D.Conditions.Add(%24protocolCondition)%3C%2FPRE%3E%3CP%3EHowever%2C%20after%20saving%20the%20endpoint%20there%20seemed%20to%20be%20no%20change%20in%20behaviour.%20Unfortunately%20then%20trying%20this%3A%3C%2FP%3E%3CPRE%3E%24ep.DeliveryPolicy%20%3D%20%24null%0ASet-AzCdnEndpoint%20-CdnEndpoint%20%24ep%3C%2FPRE%3E%3CP%3E...did%20not%20remove%20the%20policy.%20When%20retrieving%20the%20endpoint%20again%20and%20inspecting%20it%2C%20the%20policy%20is%20still%20present%20with%20all%20the%20same%20conditions%20and%20rules.%20I%20think%20Set-AzCdnEndpoint%20decided%20that%20as%20I%20wasn't%20providing%20a%20DeliveryPolicy%20I%20must%20not%20be%20wanting%20to%20alter%20the%20current%20state.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%20mechanism%20did%20clear%20out%20the%20policy%20and%20at%20least%20remove%20the%20infinite%20redirect%20problem%20(though%20no%20solution%20for%20HTTP%20%3D%26gt%3B%20HTTPS%20redirect)%3A%3C%2FP%3E%3CPRE%3E%24ep.DeliveryPolicy.Rules.Clear()%0ASet-AzCdnEndpoint%20-CdnEndpoint%20%24ep%3C%2FPRE%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F380788%22%20target%3D%22_blank%22%3E%40Braja%3C%2FA%3E%26nbsp%3Bit%20would%20be%20enormously%20useful%20if%20you%20could%20indicate%20the%20correct%20syntax%20for%20matching%20only%20HTTP%20requests%20in%20the%20conditions.%20Thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-898639%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CDN%20%E2%80%93%20Standard%20Microsoft%3A%20Rules%20Engine%20for%20http%20to%20https%20redirection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-898639%22%20slang%3D%22en-US%22%3E%3CP%3EOkay%2C%20so%20trying%20this%20again%20it%20seems%20that%20if%20I%20use%26nbsp%3B%3CEM%3Eonly%26nbsp%3B%3C%2FEM%3Ethe%20%22RequestScheme%22%20condition%20mentioned%20in%20my%20last%20comment%2C%20and%20not%20the%20%22GET%22%20condition%2C%20it%20works.%20It%20is%20also%20possible%20that%20when%20I%20tried%20to%20have%20both%20conditions%20in%20the%20rule%20yesterday%20I%20did%20not%20leave%20enough%20time%20for%20the%20policy%20to%20propagate%20before%20testing%20it.%20This%20time%20my%20successful%20tests%20were%20half%20an%20hour%20after%20applying%20the%20policy.%20Immediate%20testing%20had%20still%20shown%20that%20it%20didn't%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Use Case:

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.

 

Pre-requisites:

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,

 

  • Open PowerShell as Administrator

 

  • Run command Import-Module Az.Cdn

 

  • If the above command doesn’t throw any error, you have the Az.Cdn PowerShell module

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.

first.jpg

 

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.

2.jpg

 

  • Now to check if the Az.Cdn module is installed successfully, you can try importing the module using the command: Import-Module Az.Cdn

 

You may be prompted to confirm so that it can import this module for the first time.

3.jpg

 
  • You can also run Get-Module command to confirm if it’s imported successfully in your PowerShell session and what version it’s currently using:

 

PS command: Get-Module Az.Cdn

4.jpg

 

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.

 

Steps:

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

Connect-AzAccount

 

#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.

9 Comments

Thanks, This document has helped me a lot.

 

But, is there a way to remove the policy that has been attached.

Microsoft

@varadasandeep you're welcome.

To remove the policy from an endpoint, you can do a Get-AzCdnEndpoint to retrieve endpoint data. Once you get the endpoint data, set its deliveryPolicy to null, then do another Update-AzCdnEndpoint with the updated endpoint data.

Regular Visitor

Hello!  We keep getting the following error when trying to run the Set-AzCdnEndpoint cmdlet for a Standard Microsoft CDN Profile.  Tested on Az.Cdn 1.3.0, 1.3.3, and current Cloud Shell.

Set-AzCdnEndpoint : Operation returned an invalid status code 'BadRequest'

 

With the following in the 400 response:

"message": "A type named 'Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRedirectActionParameters' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."

 

Are you able to reproduce this?

 

Same as @jcrosbyrwb here. BadRequest on Set-AzCdnEndpoint with As.Cdn 1.3.1 Any help about this?
Microsoft

Hello @jcrosbyrwb & @technetColmar ,

I'm able to reproduce this error, seems like something has changed, I'm checking more on this internally, will post further updates on this.

Microsoft

Hello @technetColmar & @jcrosbyrwb ,

There was a fix planned to release for this issue in next 2-3 weeks, you can expect this to work by then. I'll update this thread once the fix is deployed for it.

Regular Visitor

Thank you @Braja!  We're holding up a production rollout of a site, so this fix will be much appreciated.

Occasional Visitor

This seems to have been resolved now. I just completed the steps without error today. However, this then resulted in an infinite redirect as it seemed to be matching HTTPS as well as HTTP. Given that the rule only matches GET verbs and ignores the scheme, I guess this was to be expected. I tried to guess how to add another condition:

$protocolCondition = New-AzCdnDeliveryRuleCondition -MatchVariable 'RequestScheme' -Operator Equal -MatchValue "HTTP"
$ep.DeliveryPolicy[0].Rules[0].Conditions.Add($protocolCondition)

However, after saving the endpoint there seemed to be no change in behaviour. Unfortunately then trying this:

$ep.DeliveryPolicy = $null
Set-AzCdnEndpoint -CdnEndpoint $ep

...did not remove the policy. When retrieving the endpoint again and inspecting it, the policy is still present with all the same conditions and rules. I think Set-AzCdnEndpoint decided that as I wasn't providing a DeliveryPolicy I must not be wanting to alter the current state.

 

The following mechanism did clear out the policy and at least remove the infinite redirect problem (though no solution for HTTP => HTTPS redirect):

$ep.DeliveryPolicy.Rules.Clear()
Set-AzCdnEndpoint -CdnEndpoint $ep

@Braja it would be enormously useful if you could indicate the correct syntax for matching only HTTP requests in the conditions. Thanks!

Occasional Visitor

Okay, so trying this again it seems that if I use only the "RequestScheme" condition mentioned in my last comment, and not the "GET" condition, it works. It is also possible that when I tried to have both conditions in the rule yesterday I did not leave enough time for the policy to propagate before testing it. This time my successful tests were half an hour after applying the policy. Immediate testing had still shown that it didn't work.