无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.0curl -I https://www.example.com返回200,服务器标识为Microsoft-IIS/10.0
排查推测
问题大概率发生在web.config规则处理之前,已通过IIS URL Rewrite模块验证:HTTP请求无匹配规则,导致HTTP转HTTPS规则无法触发。
咨询需求
请明确问题核心原因,并提供可行的调整方案。
内容的提问来源于stack exchange,提问作者DRestivo
相关产品推荐
相关产品推荐

