2013-03-14 74 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