.htaccess将所有带有数据的POST请求重定向到文件 [英] .htaccess redirect all POST request with data to a file

查看:95
本文介绍了.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:

重定向POST htaccess

Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix?

。htaccess将所有子目录重定向到文件

推荐答案

您使用了错误的状态代码。简而言之,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.

这篇关于.htaccess将所有带有数据的POST请求重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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