在 IIS 中测试时重定向模式匹配,而不是在浏览器中
Redirect pattern matching when testing in IIS, but not in browser
我已经在 IIS 中为站点设置了以下重定向,但它似乎根本不起作用。重定向的原因是为了摆脱旧的 Classic ASP 站点,因此理想情况下我根本不想在那里放置该文件。没有文件我得到一个 404 错误,有了文件(和映射到 text/html 的 mimetype)我正常得到文件的内容 html。没有任何反应,服务器响应始终以 HTTP 200 形式返回。
我希望 interface.asp?method=AMethod&Plant=APlant&AParameter=AValue
的请求被重定向到 example.org/interface/AMethod/APlant/AValue
在 IIS 管理器中使用我尝试打开的相同 URL 测试模式为我提供了预期的匹配项,有什么明显的我遗漏的地方吗?
<rule name="interface redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".+interface.asp\?method=(.+)&Plant=(.+)&(.+)=(.+)" />
<action type="Redirect" url="http://example.org/interface/{R:1}/{R:2}/{R:4}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
规则模式只获取URL字符串,不包含查询字符串。因此,在 URL 模式中,我们应该尝试匹配 URL 路径而不是查询字符串。查询字符串应使用 Query_String
服务器变量在 Rule Condition
中匹配。
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
根据你的 URL 规则,我纠正了它。如果问题仍然存在,请随时告诉我。
<system.webServer>
<rewrite>
<rules>
<rule name="MyRule" enabled="true" stopProcessing="true">
<match url=".*interface.asp" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="method=(.+)&Plant=(.+)&(.+)=(.+)" />
</conditions>
<action type="Redirect" url="http://example.org/interface/{C:1}/{C:2}/{C:4}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
我已经在 IIS 中为站点设置了以下重定向,但它似乎根本不起作用。重定向的原因是为了摆脱旧的 Classic ASP 站点,因此理想情况下我根本不想在那里放置该文件。没有文件我得到一个 404 错误,有了文件(和映射到 text/html 的 mimetype)我正常得到文件的内容 html。没有任何反应,服务器响应始终以 HTTP 200 形式返回。
我希望 interface.asp?method=AMethod&Plant=APlant&AParameter=AValue
的请求被重定向到 example.org/interface/AMethod/APlant/AValue
在 IIS 管理器中使用我尝试打开的相同 URL 测试模式为我提供了预期的匹配项,有什么明显的我遗漏的地方吗?
<rule name="interface redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".+interface.asp\?method=(.+)&Plant=(.+)&(.+)=(.+)" />
<action type="Redirect" url="http://example.org/interface/{R:1}/{R:2}/{R:4}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
规则模式只获取URL字符串,不包含查询字符串。因此,在 URL 模式中,我们应该尝试匹配 URL 路径而不是查询字符串。查询字符串应使用 Query_String
服务器变量在 Rule Condition
中匹配。
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
根据你的 URL 规则,我纠正了它。如果问题仍然存在,请随时告诉我。
<system.webServer>
<rewrite>
<rules>
<rule name="MyRule" enabled="true" stopProcessing="true">
<match url=".*interface.asp" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{QUERY_STRING}" pattern="method=(.+)&Plant=(.+)&(.+)=(.+)" />
</conditions>
<action type="Redirect" url="http://example.org/interface/{C:1}/{C:2}/{C:4}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>