URL重写 - 删除扩展名为.html [英] URL Rewrite - Remove .html extension

查看:233
本文介绍了URL重写 - 删除扩展名为.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的想法是从每个页面中删除.html扩展名像这样...

So the idea is to remove the .html extension from each page like so...

www.website.com/File.html > www.website.com/File
www.website.com/Folder/File.html > www.website.com/Folder/File

现在我已经成功这个使用URL重写的事,但它意味着不必编写一个重写的每一页,这是费时,效率不高,不切实际的说,如果该网站是超过20页。

Now I've managed to do this using a URL Rewrite, but it means having to write a rewrite for each page, which is time consuming, not efficient and impractical say if the website is more than 20 pages.

有没有办法写一个或两个重写在web.config中做到这一点?

Is there a way to do this by writing just one or two rewrites in the web.config?

推荐答案

该解决方案到底为我工作:

This solution worked for me in the end:

<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> 

这篇关于URL重写 - 删除扩展名为.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆