IIS 10(Windows 2019)仅重定向父页面不影响子页面的实现
IIS 10(Windows Server 2019)精准301重定向配置
要实现仅将父页面 https://www.example.com/my_current_page/ 301重定向到 https://www.example.com/New_Great_Page/,同时保留所有子页面(如 /my_current_page/Page-1)的URL不变,可通过IIS URL重写模块的精准规则实现,以下是可行的web.config配置代码:
<configuration> <system.webServer> <rewrite> <rules> <rule name="Parent Page 301 Redirect" stopProcessing="true"> <match url="^my_current_page/$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^www\.example\.com$" /> </conditions> <action type="Redirect" url="https://www.example.com/New_Great_Page/" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
规则说明
<match url="^my_current_page/$" />:用正则精确匹配路径为my_current_page/的请求,^和$确保仅匹配父页面,不会触发子页面的重定向<conditions>:限定仅匹配www.example.com域名的请求,避免站点绑定的其他域名误触发规则redirectType="Permanent":指定301永久重定向,符合SEO优化要求stopProcessing="true":执行完该规则后停止后续规则处理,避免冲突
注意事项
- 确保服务器已安装IIS URL重写模块,若未安装可通过服务器管理器的「角色和功能」添加
- 若站点根目录已有web.config文件,只需将
<rule>代码块插入到现有<rewrite><rules>节点内即可
内容的提问来源于stack exchange,提问作者user21247380
相关产品推荐
相关产品推荐

