2016-06-21 35 views
0

我想要做的是,如果我有鏈接:IIS重寫:重定向與queystring參數部分或URL的一個

http://www.test.com/photo.asp?hash=hfz6rhfgz&offset=10

爲改寫:

http://www.test.com/photo/hfz6rhfgz/?offset=10

可以有其他查詢參數和散列可能在第一個以外的其他地方...

問題是它我窩ULD的工作,但由於偏移是我的規則的第二個參數,我得到:

http://www.test.com/photo/hfz6rhfgz/&offset=10

這當然使得誤差,我需要「?」而不是「&」。在重定向的URL中,偏移量就像第二個參數,而在原始鏈接中則是第二個參數。

這裏是我的重定向規則:

  <rule name="test-redirect" stopProcessing="true"> 
       <match url="^photo.asp$" ignoreCase="true" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{QUERY_STRING}" pattern="^(.*)hash=([\w]{8})(.*)$" /> 
       </conditions> 
       <action type="Redirect" url="/photo/{C:2}/{C:1}{C:3}" redirectType="Permanent" appendQueryString="false" /> 
      </rule> 

回答

0

我自己種找到一個解決方案,但如果有類似

http://www.test.com/photo.asp?test=10&hash=jcekg876

它產生:

http://www.test.com/photo/jcekg876/?test=10&

所以最後一個放大器是在其他情況下,它工作正常。如果有人知道如何擺脫這&這將是很好的,因爲我需要一個乾淨的URL重定向...

   <rule name="test-redirect" stopProcessing="true"> 
       <match url="^photo.asp$" ignoreCase="true" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
        <add input="{QUERY_STRING}" pattern="(.*)hash=([\w]{16})[&amp;]?(.*)" /> 
       </conditions> 
       <action type="Redirect" url="/photo/{C:2}/?{C:1}{C:3}" redirectType="Found" appendQueryString="false" /> 
      </rule>