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

GoDaddy站点使用web.config移除URL中.html后缀失败求助

GoDaddy站点移除URL中.html后缀的解决方案

问题诊断

你当前遇到的问题主要有两个核心原因:

  1. 朋友提供的web.config代码中使用了中文全角引号(”“),IIS服务器解析时会直接报错,导致页面崩溃。
  2. 你错误地将原.html文件重命名为无后缀格式,但规则逻辑是让不带后缀的URL映射到对应的.html文件,重命名后服务器找不到目标文件,自然无法加载页面。

正确的web.config配置方案

替换为以下修正后的web.config代码(注意所有引号均为英文半角):

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="RewriteHTML" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
                    </conditions>
                    <action type="Rewrite" url="{R:1}.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

配置细节说明

  • 新增stopProcessing="true":避免后续规则干扰当前重写逻辑
  • 新增<add input="{REQUEST_FILENAME}.html" matchType="IsFile" />:确保只有对应的.html文件存在时才执行重写,避免无效请求报错
  • 全角引号替换为英文半角:解决IIS解析失败的核心问题

部署步骤

  1. 恢复原文件名称:将你重命名的index、services等文件改回index.html、services.html
  2. 放置web.config到正确目录:将修正后的web.config上传到网站根目录(GoDaddy Windows主机的根目录通常为public_html或wwwroot,而非public/html子目录)
  3. 等待GoDaddy自动配置生效,此时访问yourdomain.com/services会自动加载services.html,URL中不会显示.html后缀

.htaccess方案(适用于GoDaddy Linux主机)

如果你的GoDaddy站点是Linux主机,.htaccess是更常用的方案,配置代码如下:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]

部署时直接将.htaccess上传到网站根目录,保留原.html文件即可生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 07:03:12