2013-05-08 110 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> 

瞧,那开始匹配。希望这有助于未来的其他人。