【发布时间】:2020-09-28 20:19:02
【问题描述】:
我有一个用于我的网站托管的 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>
【问题讨论】:
标签: web web-config plesk