2011-09-04 59 views
1

我有这样的代码在我的web.config排除在URL目录重写

<rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^(.*)$" ignoreCase="false" /> 
    <conditions> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="default.asp?q={R:1}" appendQueryString="true" /> 
</rule> 

,我想那个特定的目录会排除这一规则。 我该怎么办?

+0

我几乎不熟悉的问题域所有,但我只是想提供思路,也许比赛节点的url属性允许你指定完整的正则表达式。如果是这样,你可以在那里列出你的目录。另一种选择是虚拟目录,但是这些都是完全的猜测。 –

+0

什么目录?请提供几个示例 – LazyOne

+0

可以说我想排除联系人和演示文稿 也,如果我想阻止目录查看(我的db目录 - 访问 - 这是一个非常小的网站),目录是在“db/site “目录 感谢您的帮助 – Chaofix

回答

14

要排除特定的文件夹(/contact//presentation//db/site/ - 这些文件夹中的任何东西)从该规则正在处理,你可以添加更多的条件,如:

<rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^(.*)$" ignoreCase="false" /> 
    <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_URI}" pattern="^/(contact|presentation|db/site)" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="default.asp?q={R:1}" appendQueryString="true" /> 
</rule> 

这是好做通过附加条件,因为它很容易阅读/理解这个规则是关于什么。


如果你善于与一般的正则表达式,那么你可能更喜欢这种方法:移动这样的情况到匹配模式(你到底有同样的结果,这将是点点快..但一有点难以阅读):

<rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^(?!(?:contact|presentation|db/site)/)(.*)$" ignoreCase="false" /> 
    <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="default.asp?q={R:1}" appendQueryString="true" /> 
</rule> 
+0

感谢您的帮助:-) – Chaofix

+0

@Chaofix如果这解决了您的问题,那么请考虑将此答案标记为已接受,thnx。 – LazyOne

+0

嗨LazyOne 不幸的是,它没有解决我的问题:-( – Chaofix

1

这是我得到了我的博客目录根和WordPress的代码点火器的工作中/博客/

博客文件夹也有原来的web.config文件这只是这个文件的第二条规则...

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <rewrite> 
     <rules>   
      <rule name="wordpress - Rule 1" stopProcessing="true"> 
       <match url="^blog" ignoreCase="false"/> 
       <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
       </conditions> 
       <action type="Rewrite" url="/blog/index.php"/> 
      </rule> 
      <rule name="app" patternSyntax="Wildcard"> 
       <match url="*"/> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
       </conditions> 
       <action type="Rewrite" url="index.php"/> 
      </rule> 
    </rules> 
</rewrite>