2010-05-07 54 views
0

我需要創建的web.config規則將改寫爲文件的所有請求與擴展的.html爲.asp和重定向所有的.asp請求爲.htmlIIS URL重寫重寫所有的.asp爲.html

例:
file_xyz.asp重寫爲file_xyz.html
directory1中/ file_xyz.asp重寫移到directory1/file_xyz.html

file_xyz.html重定向到file_xyz.asp
directory1中/ file_xyz.html重定向移到directory1 /file_xyz.asp

  1. 規則的語法是什麼
  2. 這是一個過於寬泛的規則嗎?如果我需要知道有什麼理由需要物理文件,例如file_abc.html,我該如何從重定向規則中排除它?
  3. 我想我應該只使用ISAPI_Rewrite http://www.isapirewrite.com/似乎有很多資源用於重寫htaccess,並且很少使用IIS 7 URL重寫的在線幫助。任何想法和/或建議

在此先感謝

到目前爲止,這是語法我有在web.config

<rule name="RewriteHTMLtoASP" stopProcessing="true"> 
    <match url="^([^/]+)\.html$" /> 
    <conditions logicalGrouping="MatchAll" /> 
    <action type="Rewrite" url="{R:1}.asp" /> 
    </rule> 
<rule name="RedirectASPtoHTML" stopProcessing="true"> 
    <match url="^([^/]+)\.asp$" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{REQUEST_METHOD}" pattern="^GET$" /> 
    </conditions> 
    <action type="Redirect" url="{R:1}.html" appendQueryString="false" /> 
    </rule> 
+0

聽起來像一個無限循環等待發生(ASP - > html - > asp ...) – Oded 2010-05-07 18:42:51

回答

0

看看這篇文章: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

您可以通過web.config設置重新編寫您的網頁。 如果您使用共享主機,我不會推薦使用ISAPI。

讓我知道它是否適合你。

問候,安瓦爾

+0

我有我自己的服務器,所以這只是購買ISAPI_Rewrite的許可證並安裝它或使用免費的URL與IIS 7重寫的問題。 它們都是相當複雜的學習。正則表達式語法等。 – donxythe 2010-05-09 04:17:34

3

試試這個,ü應該知道$標籤是重定向結束/重寫條件和查詢字符串將不被接受

<rule name="RewriteHTMLtoASP" stopProcessing="true"> 
       <match url="(.*).html(.*)" /> 
       <conditions logicalGrouping="MatchAll" /> 
       <action type="Rewrite" url="{R:1}.asp{R:2}" /> 
      </rule> 
      <rule name="RedirectASPtoHTML" stopProcessing="true"> 
       <match url="(.*).asp(.*)" /> 
       <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_METHOD}" pattern="^GET$" /> 
       </conditions> 
       <action type="Redirect" url="{R:1}.html{R:2}" appendQueryString="true" /> 
      </rule>