我们尝试在Microsoft Standard定价的Azure CDN上配置,以允许我们重写URL以将所有应用程序路由到./index.html。如何设置规则引擎以重写URL但将所有js文件保持不变?Google中的所有示例都展示了如何在高级定价上完成此操作,但我们希望在Microsoft Standard上实现,这可能吗?
我最终从Microsoft的支持中心得到了一个可行的答案。他们说Microsoft CDN规则引擎不支持URL文件扩展名
Not Any
,而是建议我检查文件扩展名的长度。
URL文件扩展名
不大于
0
无转换
URL重写
/
/index.html
否
这个解决方案对我有效。在测试之前,请确保清除CDN缓存。
/50D231B/endpoint-name/(.*sub-path/?)($|\?.*)
和 /50D231B/endpoint-name/(.*path)((?:[^\?]*/)?[^\?/.]+)($|\?.*)
,都重写到 /50D231B/endpoint-name/folder-on-storage/sub-path/index.html
。遗憾的是我不能完全记得这个规则的解释。 - Victor Reyes# Define Variables
$RESOURCE_GROUP_NAME = MyResourceGroup
$PROJECT = MyProject
$CDN_PROFILE_NAME = MyCDNProfile
# Create a New Http to Https Redirect Rule
$RULE_CONDITION_1 = New-AzCdnDeliveryRuleCondition -MatchVariable 'RequestScheme' -Operator 'Equal' -MatchValue 'HTTP'
$RULE_ACTION_1 = New-AzCdnDeliveryRuleAction -RedirectType 'Moved' -DestinationProtocol 'Https'
$HTTP_TO_HTTPS_RULE = New-AzCdnDeliveryRule -Name 'HttpToHttpsRedirectRule' -Order 1 -Condition $RULE_CONDITION_1 -Action $RULE_ACTION_1
# Create a New SPA Rewrite Rule
$RULE_CONDITION_2 = New-AzCdnDeliveryRuleCondition -MatchVariable 'UrlFileExtension' -Operator 'LessThan' -MatchValue '1'
$RULE_ACTION_2 = New-AzCdnDeliveryRuleAction -SourcePattern '/' -Destination '/index.html'
$SPA_REWRITE_RULE = New-AzCdnDeliveryRule -Name 'SpaRewriteRule' -Order 2 -Condition $RULE_CONDITION_2 -Action $RULE_ACTION_2
# Set the CDN Delivery Policy with the CDN Delivery Rule(s)
$CDN_DELIVERY_POLICY = New-AzCdnDeliveryPolicy -Description "Https redirect policy" -Rule $HTTP_TO_HTTPS_RULE,$SPA_REWRITE_RULE
# Get CDN Endpoint
$CDN_ENDPOINT = Get-AzCdnEndpoint -ProfileName $CDN_PROFILE_NAME -ResourceGroupName $RESOURCE_GROUP_NAME -EndpointName $PROJECT
# Assign the CDN Delivery Policy to the CDN Endpoint
$CDN_ENDPOINT.DeliveryPolicy = $CDN_DELIVERY_POLICY
# Save CDN Endpoint Changes with Updated Delivery Policy
Set-AzCdnEndpoint -CdnEndpoint $CDN_ENDPOINT
您应该会看到类似于这样的输出: