IIS URL重写模块:基于查询字符串重定向
我在基于查询字符串参数重定向到另一个URL时遇到一些问题。 例如,我有映射服务的url“http://www.mydomain.com/?lon=111&lat=222&zoom=3" 我需要把它重定向到“http://www.mydomain.com/111/222/3“ 我的web.config中有此规则,但它不起作用IIS URL重写模块:基于查询字符串重定向,iis,redirect,url-rewriting,Iis,Redirect,Url Rewriting,我在基于查询字符串参数重定向到另一个URL时遇到一些问题。 例如,我有映射服务的url“http://www.mydomain.com/?lon=111&lat=222&zoom=3" 我需要把它重定向到“http://www.mydomain.com/111/222/3“ 我的web.config中有此规则,但它不起作用 <rule name="Location redirect"> <match url="\?lon=(\d+)&lat=(\d+)&
<rule name="Location redirect">
<match url="\?lon=(\d+)&lat=(\d+)&zoom=(\d+)" />
<action type="Redirect" url="{R:1}/{R:2}/{R:3}" redirectType="Found" />
</rule>
原因是URL不包含查询字符串,您必须使用条件。如果您使用用户界面,它包含一个友好的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=([^=&]+)&lat=([^=&]+)&zoom=([^=&]+)$" />
</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}&lat={R:2}&zoom={R:3}" />
</rule>