Azure中如何将https://myfirstdomain.com/register重定向至目标域名?
解决方案:实现特定路径的永久重定向
一、Azure Functions Proxies临时启用方案
若需临时恢复Proxies功能,可直接在Function App根目录添加proxies.json文件,无需依赖门户操作,示例配置如下:
{ "$schema": "http://json.schemastore.org/proxies", "proxies": { "RegisterRedirectProxy": { "matchCondition": { "route": "/register" }, "responseOverrides": { "response.statusCode": "301", "response.headers.Location": "https://myseconddomain.com" } } } }
注意:该功能2025年将正式弃用,仅建议作为短期过渡方案。
二、Azure API Management(APIM)实现重定向步骤
- 创建API并配置路由:在APIM实例中新建API,将路由模板设置为
/register,后端服务可指向原Azure Function(或直接跳过后端配置,仅用重定向策略)。 - 添加入站重定向策略:在该API的入站策略中插入以下XML配置,实现301永久重定向:
<inbound> <base /> <return-response> <set-status code="301" reason="Moved Permanently" /> <set-header name="Location" exists-action="override"> <value>https://myseconddomain.com</value> </set-header> </return-response> </inbound>
- 绑定旧域名:将
myfirstdomain.com绑定到APIM实例,确保该域名下的/register请求全部经过APIM处理。
三、低成本简便方案:DNS+目标站点配置
如果旧域名仅需处理/register路径的重定向,可采用以下两步实现:
- DNS解析配置:将
myfirstdomain.com的CNAME记录指向myseconddomain.com,同时确保目标App Service已添加该旧域名的自定义域名绑定。 - 目标站点重定向规则:
- 若目标是.NET App Service,在
web.config中添加重写规则:
<rewrite> <rules> <rule name="RegisterRedirect" stopProcessing="true"> <match url="^register$" /> <conditions> <add input="{HTTP_HOST}" pattern="^myfirstdomain.com$" /> </conditions> <action type="Redirect" url="https://myseconddomain.com" redirectType="Permanent" /> </rule> </rules> </rewrite>- 若目标是Linux App Service,修改
nginx.conf添加规则:
server { listen 80; server_name myfirstdomain.com; location = /register { return 301 https://myseconddomain.com; } } - 若目标是.NET App Service,在
内容的提问来源于stack exchange,提问作者Fabian Bigler
相关产品推荐
相关产品推荐

