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

无www域名301跳转正常但www域名返回404问题排查求助

问题:www.example.com HTTP请求返回404,根域名跳转正常

问题背景

需实现www.example.com与example.com两个版本URL均正常解析,目前仅根域名可正常跳转(302),但www域名的HTTP请求返回404,需明确问题原因并提供生产环境可执行的解决方案。

现有配置信息

  • web.config 非www转www永久重定向规则:
<rule name="redirect non-www to www"  stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
  • 后端C#跳转逻辑:从数据库获取域名拼接HTTPS地址,该流程在其他客户端运行正常
subdomain = "https://" + urlRow["DomainMask"].ToString();
return Redirect(subdomain);
  • DNS配置:
example.com.      0       IN      CNAME   our.domain.com.
our.domain.com.         0       IN      A       IP.Address
  • HSTS配置:根域名已启用 Strict-Transport-Security:max-age=31536000; includeSubDomains; preload
  • web.config HTTP转HTTPS重定向规则(位于非www转www规则之后):
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" appendQueryString="false" />
</rule>

测试结果

  • curl -I http://www.example.com 返回404,服务器标识为 Microsoft-HTTPAPI/2.0
  • curl -I https://www.example.com 返回200,服务器标识为 Microsoft-IIS/10.0

排查推测

问题大概率发生在web.config规则处理之前,已通过IIS URL Rewrite模块验证:HTTP请求无匹配规则,导致HTTP转HTTPS规则无法触发。

咨询需求

请明确问题核心原因,并提供可行的调整方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 19:12:42