仅对具有.html而没有首页的URL使用web.config从URL中删除.html扩展名

问题描述

我有一个用于托管网站的Plesk帐户。我对web.config文件一无所知,但是我试图从URL中删除.HTML扩展名。我尝试了一个解决方案(在后面的文章中编写),但是它对除主页之外的所有URL都非常有效。我的主页显示以下错误:

“ /”应用程序中的服务器错误。

运行时错误

(上面的错误中有更多文本,但是我试图使问题尽可能简短)

当我使用www.xyz.com时会显示错误。使用www.xyz.index.html时,它可以正常工作,但随后我看到的URL变成了www.xyz.index,这看起来很不愉快。请参阅下面的这篇文章,如果可以的话,请帮助我解决问题!

Remove HTML extension with web config permanently

写为上述文章的最佳答案以及我正在使用的最佳答案的代码:

<configuration>   
    <system.webServer>   
        <rewrite>
            <rules>
                <rule name="Hide .html ext">
                    <match ignoreCase="true" url="^(.*)"/>
                    <conditions>
                        <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:0}.html"/>
                </rule>
                <rule name="Redirecting .html ext" stopProcessing="true">
                    <match url="^(.*).html"/>
                    <conditions logicalGrouping="MatchAny">
                        <add input="{URL}" pattern="(.*).html"/>
                    </conditions>
                    <action type="Redirect" url="{R:1}"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

解决方法

啊,我知道怎么了。是因为您忘记了/,或者是因为它是一个文件夹,或者是因为您使用了多个域。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...