You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure App Service多URL永久重定向:web.config是否适用?

用web.config实现多条特定URL永久重定向

完全可以通过web.config配置IIS URL重写规则来实现这类需求,核心是借助IIS URL重写模块(需确保服务器已安装该模块)。以下是具体配置方案:

配置示例

在web.config的<system.webServer>节点内添加<rewrite>配置块,每条特定URL对应一条<rule>规则,示例如下:

<system.webServer>
  <rewrite>
    <rules>
      <!-- 第一条重定向规则 -->
      <rule name="Redirect Old URL 1" stopProcessing="true">
        <match url="^route$" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$" />
          <add input="{QUERY_STRING}" pattern="^someID=123&otherId=4356$" />
        </conditions>
        <action type="Redirect" url="https://newsubdomain.newexample.com/route?newID=34563456456" redirectType="Permanent" />
      </rule>

      <!-- 第二条重定向规则(可复制此结构添加剩余14条) -->
      <rule name="Redirect Old URL 2" stopProcessing="true">
        <match url="^another-route$" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="^subdomain\.example\.com$" />
          <add input="{QUERY_STRING}" pattern="^someID=456&otherId=7890$" />
        </conditions>
        <action type="Redirect" url="https://newsubdomain.newexample.com/another-route?newID=789078907890" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

关键配置说明

  • <rule>的name属性:为每条规则设置唯一标识,方便维护
  • <match url>:匹配旧URL的路径部分(注意正则表达式的转义,比如^route$精确匹配路径/route)
  • <conditions>:通过{HTTP_HOST}匹配旧域名,{QUERY_STRING}精确匹配旧URL的查询参数
  • <action>:设置重定向类型为Permanent(即301永久重定向),url指定目标新URL

你只需按照上述结构,复制并修改<rule>节点,就能完成15条特定URL的重定向配置。

内容的提问来源于stack exchange,提问作者TunedBy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 09:09:51