2010-11-10 165 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