.htaccess将所有带有数据的POST请求重定向到文件
我在子文件夹(www.domain.com/API/)中有一个 .htaccess
文件,我需要将该子文件夹的所有POST请求重定向到以下位置的文件中一个子文件夹(www.domain.com/API/Sub/manager.php)
I have a .htaccess
file in a subfolder (www.domain.com/API/) and I need to redirect all POST requests of this subfolder into a file in a subfolder (www.domain.com/API/Sub/manager.php)
我必须说所有POST请求都将包含数据(2-10个参数)和所有数据
I must say all POST requests will have data (2-10 parameters) and all data most be redirect too.
我已经阅读了一些帖子和页面,但它们不能解决我的情况。
I have read some posts and pages but they cannot solve my situation.
我有以下规则:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://www.example.net/API/Sub/manager.php [QSA,L]
但是,我得到的东西是:
However, I got something like:
302找到->文档已移动(链接到
ww.domain.com/API/Sub/manager.php)
302 Found --> The document has moved (link to ww.domain.com/API/Sub/manager.php)
Can somebody tell me what I am doing wrong?
谢谢。
这些是我浏览过的页面:
P.S. These are some pages I looked into:
Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix?
您使用了错误的状态代码。简而言之,302代码并不要求浏览器重新传输所有数据(POST请求);您需要改用307代码。
You are using the wrong status code. In a nutshell, the 302 code is not requesting that the browser retransmit all data (the POST request); you need to use the 307 code instead.
要在Apache下执行此操作,请将最后一条规则更新为
To do this under Apache, update that last rule to end with
[QSA,L,R = 307]
[QSA,L,R=307]
如果您是唯一对POST数据感兴趣,您甚至不需要QSA标志。
If you are only interested in the POST data, you don't even need the QSA flag.
有关gory的详细信息,您可以查看HTTP状态代码的完整列表及其含义此处。在协议页面上明确指出了302代码未按您希望的方式运行的原因(强调我的意思)
For the gory details, you can see the entire list of HTTP status codes and their meanings here. The reason the 302 code is not functioning the way you want it to is explicitly called out in on the protocols page as follows (emphasis mine)
注意:RFC 1945和RFC 2068指定不允许客户端
更改重定向请求的方法。但是,大多数现有的
用户代理实现将302视为303
响应,无论原始请求方法的
如何,都对Location字段值执行GET >。为希望明确弄清客户端期望哪种
反应的服务器添加了状态代码303和307
。
Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.