在IIS7中重写URL

在IIS7中重写URL,iis,iis-7,url-rewriting,web-config,Iis,Iis 7,Url Rewriting,Web Config,我一直在遵循,这是一个近乎完美的指南,以创建搜索引擎优化友好的网址IIS7 但我有一个问题: 如果我创建了一个重写www.domain.com/contact/的规则,我会进入web.config: <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> <match url="^([^/]+)/?$" /> <conditions> <add input="{REQUEST

我一直在遵循,这是一个近乎完美的指南,以创建搜索引擎优化友好的网址IIS7

但我有一个问题:

如果我创建了一个重写
www.domain.com/contact/
的规则,我会进入web.config:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
  <match url="^([^/]+)/?$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="?p={R:1}" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
  <match url="^([^/]+)/([^/]+)/?$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="?p={R:1}&amp;a={R:2}" />
</rule>
但是我不能做
www.domain.com/contact/

这两条规则都可以使我看不到我的
/scripts/
/css/
/images/
文件夹中的任何脚本、css og图像


我如何制定一个规则来匹配上述三个文件夹,而不匹配它们?

您的规则可以是这样的(为了便于理解和最终编辑,我对其进行了扩展和注释):

这可以转化为以下内容:

<match url="^((?!css|scripts|images)[^/]+)(/(([^/]+)/?)?)?$" />


然后,重写url应更新为:
?p={R:1}&;a={R:4}
因为新正则表达式的捕获数量发生了变化。

这太完美了。。非常感谢!:)
<match url="^((?!css|scripts|images)[^/]+)(/(([^/]+)/?)?)?$" />