2012-04-18 164 views
6

這樣的想法是從像這樣每個頁面中刪除擴展名爲.html ...URL重寫 - 刪除擴展名爲.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中只寫入一個或兩個重寫來做到這一點?

+0

我也想知道!幫助SO用戶UNITE! – 2012-04-18 14:22:39

回答

9

該方案最終爲我工作:

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

不錯的一個Ryano!我會爲您投票 - 但我們已被告知過去投票... – 2012-04-18 14:36:22

+3

不幸的是,這也會刪除.css,.js和其他擴展程序 – CarneyCode 2016-01-09 15:13:05