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

如何在IIS 10中配置浏览时自动显示完整URL路径?

IIS 10 URL重定向:将根路径统一为带index.html的完整URL

核心规则逻辑

用301永久重定向规则匹配所有以/结尾的请求(含主站根路径、子站点根路径),重定向到追加index.html后的完整URL。301跳转能让搜索引擎和用户识别为永久路径变更,彻底统一Google Analytics的统计维度,解决重复计数问题。

具体配置代码

在站点或子站点的web.config文件中,找到<system.webServer>节点,插入以下URL Rewrite规则:

<rewrite>
  <rules>
    <!-- 重定向主站根路径 / 到 /index.html -->
    <rule name="Redirect Root to index.html" stopProcessing="true">
      <match url="^$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
      </conditions>
      <action type="Redirect" url="/index.html" redirectType="Permanent" />
    </rule>
    <!-- 重定向子站点根路径(如 /subsite/)到 /subsite/index.html -->
    <rule name="Redirect Subdirectory Roots to index.html" stopProcessing="true">
      <match url="^(.*)/$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
        <add input="{REQUEST_FILENAME}\index.html" matchType="IsFile" negate="false" />
      </conditions>
      <action type="Redirect" url="{R:1}/index.html" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

关键说明与注意事项

  • 先确认IIS已安装URL Rewrite模块:若未安装,需在服务器管理器的角色功能中添加「URL Rewrite」组件。
  • 验证规则有效性:配置后直接访问主站根域名或子站点路径,检查地址栏是否自动跳转至带index.html的URL;也可通过浏览器开发者工具的「网络」标签,确认跳转状态码为301。
  • 适配自定义默认文档:如果站点默认文档不是index.html(如default.html),只需将规则中的index.html替换为对应文件名即可。
  • 子站点独立配置:若子站点有独立web.config,建议单独添加规则,避免继承主站配置引发冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 16:11:16