.net - URL 重写 - 删除 .html 扩展名

标签 .net html iis url-rewriting web-config

所以想法是像这样从每个页面中删除 .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/

相关文章:

c# - 超时不适用于 WebRequest

c# - 如何将 ListBox 绑定(bind)到 XML 文件中的对象列表?

asp.net - 如何在 IIS7.0 上解析 "HTTP Error 500.19 - Internal Server Error"

asp.net-mvc - 仅在应用程序池回收后 MVC 应用程序上的 CheckVirtualFileExists 异常

asp.net - IIS 7 忽略没有文件扩展名的 MapPageRoute

c# - 使用用作 protected 字段的内部类型

c# - NetworkInterface.GetIPv4Statistics().BytesReceived - 它返回什么?

html - Next.js "Image"与普通 "img"标签中的图像质量较低

html - css margin-top 压低了我的页脚

html - 如何在 UIWebView 中显示 HTML 代码?