2012-01-11 62 views
3

我一直在关注http://learn.iis.net/page.aspx/806/seo-rule-templates/,这是一个在IIS7中创建搜索引擎友好URL的几乎完美的指南。在IIS7中重写URL

我虽然一个问题:

如果我创建一个规则来重写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> 

但后来我做不到www.domain.com/contact/send/

如果我创建一个规则来重写www.domain.com/contact/send/我得到在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}&amp;a={R:2}" /> 
</rule> 

但我不能这样做www.domain.com/contact/

两者的规则去做,让我看不到任何脚本,来自我的/scripts/,/css//images/文件夹的css或og图像。

我该如何制定一条规则来匹配AND和NOT以匹配上面提到的3个文件夹?

+0

没有人能回答我这个问题吗? :/ – Behrens 2012-01-12 10:14:21

回答

3

你的规则可以是这样的(我已经扩大,并评论它更容易理解和最终编辑):

^ 
    (
     (?!css|scripts|images) # The directories you don't want to match 
     [^/]+     # The matched directory 
    ) 
    (
     /
     (
      ([^/]+)    # Optional part 
      /?     # Optional trailing slash 
     )? 
    )? 
$ 

换算成以下几点:

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

重写由于新正则表达式捕获次数的变化,网址应该更新为:?p={R:1}&amp;a={R:4}

+0

这是完美的..非常感谢! :) – Behrens 2012-01-18 16:01:01

+0

不客气! – 2012-01-18 16:48:56