2013-03-14 41 views
2

我尝试使用URL重写IIS模块以将URL修改为具有原始URL路径中包含的参数的另一个URL。使用URL重写将参数添加到URL

经验: 原始地址:myurl/specialattribute_123456

通缉网址:myurl specialattribute = 123456

我已经使用URL重写模块,并在web.config此标记生成:

<rewrite> 
    <rules> 
    <rule name="RedirectRule1" stopProcessing="true"> 
     <match url=".*/specialattribute_(.*)/" /> 
     <action type="Redirect" url="myurl?specialattribute={R:1}" /> 
       </rule> 
    </rules> 
    <outboundRules> 
      <preConditions> 
       <preCondition name="ResponseIsHtml1"> 
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> 
       </preCondition> 
      </preConditions> 
    </outboundRules> 
</rewrite> 

但它没有工作......任何帮助?

回答

0

问题解决了:

什么在URL中匹配标记是在您的网站的基本网址之后发生的。

<match url="specialattribute_(.*)" /> <action type="Redirect" url="myurl?webserviceid={R:1}" redirectType="Temporary" />

0

试试这个:

<match url="*/specialattribute_*" /> 
     <action type="Redirect" url="myurl?specialattribute={R:2}" /> 

只要确保你在你的UrlRewrite模块规则设置使用“通配符”。

+0

谢谢回答我,有地方“*”和“/”不能是连续的......还停留 – user2087284 2013-03-15 15:09:12

0

您的问题属于您正在使用的模式。

您的规则不符合myurl/specialattribute_123456但确实符合myurl/specialattribute_123456/

如果你希望你的模式匹配myurl/specialattribute_123456在你的榜样,你的规则模式更改为(只需删除后/):

<match url=".*/specialattribute_(.*)" /> 
+0

谢谢你,我做了你的建议,但是...我有一个错误404找不到myurl/specialattribute_123 ...可能是入站/出站的问题吗?我读过[link](http://forums.iis.net/t/1173449.aspx/1)入站规则用于修改HTTP请求URL,而出站规则用于修改HTTP响应。也许这就是问题所在...... – user2087284 2013-03-15 15:05:28

+0

你想使用'outboundRules'做什么?如果你把它拿走了怎么办? – cheesemacfly 2013-03-15 15:22:29

+0

我已经把这个: <规则名称= “RedirectRule1” stopProcessing = “真”> \t <匹配URL = “*/specialattribute _(*)。”/> <动作类型=“重定向? “URL =” myurl参数1 = {R:2} “<! - /> \t <先决条件> <前提名称= ”ResponseIsHtml1“> <添加输入=”{ RESPONSE_CONTENT_TYPE}“pattern =”^ text/html“/> \t - > 同样的错误为浏览时myurl /当然myurl的specialattribute_123 只工作正常 – user2087284 2013-03-15 16:31:17