我有一个主代理,它将请求发送到安装了 OpeenSSO 的辅助代理。
如果 OpenSSO 代理确定用户未登录,则会向身份验证服务器发出 302 重定向,并提供用户请求的原始(编码)URL 作为重定向位置 header 中的 GET 参数。
但是,GET 变量中的 URL 是内部(辅助)代理服务器的 URL,而不是原始代理服务器的 URL。因此,我想编辑/重写“位置”响应 header 以提供正确的 URL。
例如。
我已经尝试了几乎所有标题和重写的组合而没有运气,所以我认为这可能是不可能的。我得到的最接近的是这个,但是 mod_headers 编辑函数不解析环境变量。
# On the primary proxy.
RewriteEngine On
RewriteRule ^/(.*)$ - [E=orig_request:$1,P]
Header edit Location ^(http://auth\.a\.com/login/\?orig_request=).*$ "$1http%3A%2F%2Fa.com%2F%{orig_request}e"
最佳答案
代理密码反向
ProxyPassReverse应该为你做这个:
This directive lets Apache adjust the URL in the Location, Content-Location and URI headers on HTTP redirect responses.
假设您使用一对 ProxyPass 和 ProxyPassReverse 指令来定义它,我不确定为什么您的反向代理还没有这种行为。
编辑位置标题
如果您希望能够按照您的描述编辑 Location 标题,您可以这样做 as of Apache 2.4.7 :
For edit there is both a value argument which is a regular expression, and an additional replacement string. As of version 2.4.7 the replacement string may also contain format specifiers.
文档中提到的“格式说明符”包括能够使用环境变量,例如
%{VAR}e
.您可能还想考虑修改您的应用程序,使 orig_request URL 参数相对化,从而可能不需要使用环境变量进行 Header 编辑。
相对路径位置 header
您还可以尝试在 Location header 中使用相对路径,这样就无需将一个域显式映射到另一个域。这是正式有效的as of RFC 7231 (2014 年 6 月),but was was widely supported even before that .您可以使用 Apache
Header edit
相对化您的 Location header 指令(甚至在 2.4.7 版之前,因为它不需要环境变量替换)。这看起来像这样:Header edit Location "(^http[s]?://)([a-zA-Z0-9\.\-]+)(:\d+)?/" "/"
关于apache - 如何在使用 Apache 的代理设置中重写位置响应 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297233/