问题描述
我有一个用于托管网站的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>
解决方法
啊,我知道怎么了。是因为您忘记了/,或者是因为它是一个文件夹,或者是因为您使用了多个域。