2016-08-10 125 views
1

我有這些規則在我的web.config設置:如何排除從規則目錄在Web.config中(ASP.NET)

<rules> 
     <rule name="replacedash"> 
      <match url="(.*)(-)(.*)\.aspx$" /> 
      <action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" /> 
     </rule> 
     <rule name="extensionless" stopProcessing="true"> 
       <match url="(.*)\.aspx$" /> 
       <action type="Redirect" url="{R:1}" redirectType="Permanent" /> 
     </rule> 
     <rule name="removeextension" enabled="true"> 
      <match url=".*" negate="false" /> 
       <conditions> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        <add input="{URL}" pattern="(.*)\.(.*)" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="{R:0}" /> 
     </rule> 
    </rules> 

我已經升級了我的網站從簡單的ASP.NET到ASP。 NET MVC和我已經寫了這些規則,以防萬一在搜索引擎中仍然存在一些帶.aspx擴展名的舊緩存鏈接;然而,我的web服務器上有一些目錄仍然包含.aspx文件,這是因爲很好的原因,我的規則也重寫了這些擴展。

如何從繼承我的規則中排除這些文件夾?

回答

6

主要基於以下這裏的解決方案:

How to exclude a directory with IIS URL rewriting?

你可以做這樣的事情:

<rules> 
    <rule name="ignore web forms folder 1" stopProcessing="true"> 
     <match url="^webformsfolder1/" /> 
     <action type="None" /> 
    </rule> 
    <rule name="ignore web forms folder 2" stopProcessing="true"> 
     <match url="^webformsfolder2/" /> 
     <action type="None" /> 
    </rule> 
    <rule name="ignore web forms folder 3" stopProcessing="true"> 
     <match url="^webformsfolder3/" /> 
     <action type="None" /> 
    </rule> 
    <rule name="replacedash"> 
     <match url="(.*)(-)(.*)\.aspx$" /> 
     <action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" /> 
    </rule> 
    <rule name="extensionless" stopProcessing="true"> 
      <match url="(.*)\.aspx$" /> 
      <action type="Redirect" url="{R:1}" redirectType="Permanent" /> 
    </rule> 
    <rule name="removeextension" enabled="true"> 
     <match url=".*" negate="false" /> 
      <conditions> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       <add input="{URL}" pattern="(.*)\.(.*)" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="{R:0}" /> 
    </rule> 
</rules> 
相關問題