在Apache上重定向(保持POST参数) [英] Redirection on Apache (Maintain POST params)

查看:507
本文介绍了在Apache上重定向(保持POST参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上安装了Apache,我需要从http重定向到https.这样做的原因是我们的负载均衡器解决方案无法处理https,因此请求来自http,然后我们使用httpd.conf文件中的以下几行将其传输到https.

I have Apache installed on my server and I need to redirect from http to https. The reason for this is our load balancer solution cannot hand https so requests come in on http and then we transfer them to https using the below lines in the httpd.conf file.

<VirtualHost 10.1.2.91:80>
     Redirect 302 /GladQE/link https://glad-test.com/GladQE/link.do
</VirtualHost>

这对于GET请求很好用,但是POST请求将丢失在URL上传递的参数.执行此重定向和维护POST参数的最简单方法是什么?

This works fine for GET requests but POST requests will lose the parameters passed on the URL. What would be the easiest way to perform this redirect and maintain POST params?

我需要从 http://glad-test.com/GladQE/link获取信息. 转到此处 https://glad-test.com/GladQE/link.do 维护POST参数

I need to get from http://glad-test.com/GladQE/link.do to here https://glad-test.com/GladQE/link.do maintaining POST params

谢谢

汤姆

推荐答案

标准Apache重定向在URL级别上工作时将无法处理POST数据. POST数据在请求的主体中传递,如果您执行标准重定向,则该数据将被丢弃.

Standard Apache redirects will not be able to handle POST data as they work on the URL level. POST data is passed in the body of the request, which gets dropped if you do a standard redirect.

您可以选择使用PHP脚本透明地转发POST请求,或者将Apache的Rewrite(mod_rewrite)和Proxy(mod_proxy)模块结合使用,如下所示:

You have an option of either using a PHP script to transparently forward the POST request, or using a combination of Rewrite (mod_rewrite) and Proxy (mod_proxy) modules for Apache like follows:

RewriteEngine On
RewriteRule /proxy/(.*)$ http://www.example.com/$1 [P,L]

P标志将请求传递到代理模块,因此,以/proxy/开头的URL路径(通过GET或POST无关)到达您网站的任何内容都将透明地作为代理重定向处理到http://www.example.com/.

P flag passes the request to the Proxy module, so anything that comes to your site (via GET or POST doesn't matter) with a URL path starting with a /proxy/ will transparently be handled as a proxy redirect to http://www.example.com/.

供参考:

  • http://httpd.apache.org/docs/current/mod/mod_rewrite.html
  • http://httpd.apache.org/docs/current/mod/mod_proxy.html

这篇关于在Apache上重定向(保持POST参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆