【问题标题】:Forward query string with ErrorDocument in apache在apache中使用ErrorDocument转发查询字符串
【发布时间】:2016-11-02 21:25:15
【问题描述】:

发生错误时,我正在尝试转发到另一台主机。我有这个,并且可以工作:

<VirtualHost *:80>
    ServerName test.com.
    ServerAlias test.com

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse /  http://127.0.0.1:8080/

    RewriteEngine on

    ErrorDocument 503 /503/

    RewriteCond %{REQUEST_URI} ^/503/$
    RewriteRule ^(.*)$ http://other.host.com/

</VirtualHost>

现在,当我有这个 URL:http://test.com/path/?param1=val1&amp;param2=val2 并且出现 503 错误时,我想重定向到新的 URL:http://other.host.com/path/?param1=val1&amp;param2=val2

是否可以将 /path/?param1=val1&param2=val2 转发到新主机?

我见过thisthis,但这不完全是我的问题。

PS:我运行的是 java 应用程序,而不是 php 应用程序

【问题讨论】:

    标签: apache .htaccess ubuntu


    【解决方案1】:

    从Apache 2.4.13开始,ErrorDocument也可以使用表达式,所以:

    ErrorDocument 503 http://other.host.com/%{REQUEST_URI}?%{QUERY_STRING}
    ProxyErrorOverride on
    

    【讨论】:

    • 谢谢@julp,这行得通!我没有添加ProxyErrorOverride on 并且也工作过。我已将 apache 升级到 2.4.20。非常感谢。
    【解决方案2】:

    在 Apache 2.2 上的 shell 脚本 CGI 和 PHP 中测试

    在 shell 脚本 CGI 中,转储 /bin/env 变量和 grep REQUEST_URI

    在 PHP 中,ret $_SERVER['REQUEST_URI']

    此技巧适用于保持来自 httpd.conf 设置的查询字符串重定向。

    ErrorDocument 401 /errCode/401.html
    

    【讨论】:

      猜你喜欢
      • 2011-03-02
      • 2014-07-27
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多