所以想法是像这样从每个页面中删除 .html 扩展名......
www.website.com/File.html > www.website.com/File
www.website.com/Folder/File.html > www.website.com/Folder/File
现在我已经设法使用 URL 重写来做到这一点,但这意味着必须为每个页面编写一个重写,这很耗时,效率不高且不切实际,比如网站超过 20 页。
有没有办法通过在 web.config 中编写一两个重写来做到这一点?
最佳答案
这个解决方案最终对我有用:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^(.*)\.(.*)$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.(.*)" />
</rule>
关于.net - URL 重写 - 删除 .html 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210936/