2010-11-10 173 views
1

我在根據查詢字符串參數重定向到另一個URL時遇到了一些問題。 我有映射服務的網址,例如「http://www.mydomain.com/?lon=111 & lat = 222 & zoom = 3」 我需要將它重定向到「http:// www。 mydomain.com/111/222/3" 。IIS URL重寫模塊:基於查詢字符串重定向

我在我的web.config這條規則,但它不工作

<rule name="Location redirect"> 
    <match url="\?lon=(\d+)&amp;lat=(\d+)&amp;zoom=(\d+)" /> 
    <action type="Redirect" url="{R:1}/{R:2}/{R:3}" redirectType="Found" /> 
</rule> 

回答

2

的原因是URL不包括查詢字符串,你定義使用爲條件。如果您使用用戶界面,它會包含一個友好的網址模板,可以爲您生成。 下面你會發現重寫規則以及重定向使傳統業務(醜陋的URL)被重定向到URL漂亮:

  <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> 
       <match url="^$" /> 
       <conditions> 
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
        <add input="{QUERY_STRING}" pattern="^lon=([^=&amp;]+)&amp;lat=([^=&amp;]+)&amp;zoom=([^=&amp;]+)$" /> 
       </conditions> 
       <action type="Redirect" url="/{C:1}/{C:2}/{C:3}" appendQueryString="false" /> 
      </rule> 
      <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="?lon={R:1}&amp;lat={R:2}&amp;zoom={R:3}" /> 
      </rule> 
+0

非常感謝您! – 2010-11-11 11:25:45