如何解决仅对具有.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>
解决方法
啊,我知道怎么了。是因为您忘记了/,或者是因为它是一个文件夹,或者是因为您使用了多个域。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。