2012-03-07 93 views
0

我一直在关注以下IIS资源文章的步骤,以便使用模式捕获源URL并基于下面的正则表达式。使用重写模块IIS7重定向

http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module

源(OLD)URL:http://xx.xx.xxx.xx/term/product/term-term/category/example-123/58276 图案:HTTP://xx.xx.xxx.xx/term/([AZ] +)/([AZ-] +)/([在IIS7中测试源URL的模式可以正常工作。目的地URL如下需要维持IP随后/产品,其是R:1和/ 582276,其是R:5

连结网址:http://xx.xx.xxx.xx/ {R:1}/{R:5} 因此实际目的地(NEW)URL是http://xx.xx.xxx.xx/product/58276

但是上述使用的浏览器,而是得到一个恼人的404

我的web.config文件时不工作看起来像

`

 <rules> 

      <rule name="PatternRedirect" stopProcessing="true"> 

       <match url="http://xx.xx.xxx.xx/term/([a-z]+)/([a-z-]+)/([a-z]+)/([0-9a-z-]+)/([0-9]+)" /> 

       <action type="Redirect" url="http://xx.xx.xxx.xx/{R:1}/{R:5}" /> 

      </rule> 

     </rules> 

    </rewrite> 

    <httpRedirect enabled="true" destination="" exactDestination="true" httpResponseStatus="Permanent" /> 

`

任何想法?

由于

回答

1

用于模式匹配的输入值是除领先/(正斜杠)的URL的路径部分。匹配元素的url属性必须以“术语”启动:

<match url="term/([a-z]+)/([a-z-]+)/([a-z]+)/([0-9a-z-]+)/([0-9]+)" /> 

如果你想确保规则仅适用于xx.xx.xxx.xx主机的请求,加入条件:

<conditions logicalGrouping="MatchAll"> 
    <add input="{HTTP_HOST}" pattern="^xx.xx.xxx.xx$" /> 
</conditions> 
+0

真的很感激。这工作完美。 – user1171048 2012-03-08 11:19:43