2013-05-08 119 views
0

我設置了,看起來像這樣的應用程序中的文件夾結構:IIS重寫根文件夾不同的子文件夾

  • C:\的Inetpub \ wwwroot的\ CONTOSO \公共
  • C:\的Inetpub \ wwwroot的\ CONTOSO \安全

我想下面的URL映射到這些文件夾結構:

我已經安裝在服務器上的Application Request Routing Version 2。我的思維過程是,我可以多建幾個重寫規則做的映射關係對我這樣,因爲這些...

<rewrite> 
    <rules> 
     <rule name="Rewrite pub page to aspx" stopProcessing="false"> 
      <match url="^([a-z0-9/]+)$" ignoreCase="true" /> 
      <conditions> 
       <add input="public\{REQUEST_FILENAME}.aspx" matchType="IsFile" ignoreCase="true" /> 
      </conditions> 
      <action type="Rewrite" url="public/{R:1}.aspx" /> 
     </rule> 
     <rule name="Rewrite sec page to aspx" stopProcessing="false"> 
      <match url="^([a-z0-9/]+)$" ignoreCase="true" /> 
      <conditions> 
       <add input="secured\{REQUEST_FILENAME}.aspx" matchType="IsFile" ignoreCase="true" /> 
      </conditions> 
      <action type="Rewrite" url="secured/{R:1}.aspx" /> 
     </rule> 
     <rule name="Rewrite 404 page to aspx" stopProcessing="true"> 
      <match url="^([a-z0-9/]+)$" ignoreCase="true" /> 
      <conditions> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
      </conditions> 
      <action type="Rewrite" url="public/default.aspx" /> 
     </rule> 
    </rules> 
</rewrite> 
<location path="secured"><system.web><authorization><deny users="?"/></authorization></system.web></location> 
<location path="public"><system.web><authorization><allow users="?,*"/></authorization></system.web></location> 

在我心中,我說的是條件,以檢查文件中的公共文件夾中存在如果是的話,它會重寫該文件。否則,它會告吹,看看文件中的安全文件夾存在,如果是這樣,將改寫該文件。否則,它會被「一蹴而就」規則所捕獲,並將其指回默認頁面。

但是這不工作對我的期望......我可以得到它總是改寫到一個文件夾,但我不能讓條件消防檢查現有的文件。

有什麼建議嗎?

回答

0

我打開IIS中的跟蹤上,並通過這些日誌,我能夠發現{} REQUEST_FILENAME看是錯誤的變量在這種情況下使用。下面是相關的日誌信息:

Input secured\{REQUEST_FILENAME}.aspx 
ExpandedInput secured\c:\inetpub\wwwroot\contoso\myaccount.aspx 
MatchType 1 
Pattern 
Negate false 
Succeeded false 
MatchType IsFile 

所以我去翻翻server variables list documentation,並能找到APPL_PHYSICAL_PATH變量,改變了輸入這樣的:

 <rule name="Rewrite sec page to aspx" stopProcessing="false"> 
      <match url="^([a-z0-9/]+)$" ignoreCase="true" /> 
      <conditions> 
       <add input="{APPL_PHYSICAL_PATH}secured\{R:1}.aspx" matchType="IsFile" ignoreCase="true" /> 
      </conditions> 
      <action type="Rewrite" url="secured/{R:1}.aspx" /> 
     </rule> 

瞧,那開始匹配。希望這有助於未來的其他人。