我使用IIS 10作为反向代理来托管网页(3方,我无法修改代码)。
本地:localhost:26982
外部:sub.domain.com
外部请求被重定向到本地实例。我为此使用以下重写规则(web.config):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^sub.domain.com$" />
</conditions>
<action type="Rewrite" url="http://localhost:26982/{R:1}" />
</rule>
</rules>
<outboundRules>
</outboundRules>
</rewrite>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="strict-transport-security" value="max-age=16070400" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</configuration>
[当用户尝试登录页面时,它将重定向到OpenID提供程序(Steam-使用HTTP302-标头中的返回URL)。不幸的是,在路径中编码的return url
仍然包含http://localhost:26982
(编码为:http%3A%2F%2Flocalhost%3A26982
),而不包含http://sub.domain.com
。请求/重定向如下所示:
当我在localhost
上尝试时,它看起来相同,并且工作正常。但是,当身份验证成功时,由于显而易见的原因,在使用sub.domain.com
时重定向不起作用。
解码的正确方法是什么=>重写=>重新编码URL路径段?
[如果有人对此也有疑问,我发现了一个可行的解决方案,但需要反复尝试。
<outboundRules>
<rule name="Rewrite Header" preCondition="IsRedirect">
<match serverVariable="RESPONSE_Location" pattern="^https://(steamcommunity.com)/(.*)(return_to=http%3A%2F%2Flocalhost%3A26982)(.*)(realm=http%3A%2F%2Flocalhost%3A26982)(.*)" />
<conditions>
<add input="{R:1}" pattern="steamcommunity.com" />
</conditions>
<action type="Rewrite" value="https://{R:1}/{R:2}return_to=https%3A%2F%2Fsub.domain.com{R:4}realm=https%3A%2F%2Fsub.domain.com{R:6}" />
</rule>
<preConditions>
<preCondition name="IsRedirect">
<add input="{RESPONSE_STATUS}" pattern="3\d\d" />
</preCondition>
</preConditions>
</outboundRules>
这将使用新值重写任何HTTP 3XX重定向位置。
[如果有更好的解决方案,请告诉我,但是目前,这对我有效。