2

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)

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.

I have this rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://www.example.net/API/Sub/manager.php [QSA,L]

However, I got something like:

302 Found --> The document has moved (link to ww.domain.com/API/Sub/manager.php)

Can somebody tell me what I am doing wrong?

Thank you in advance.

P.S. These are some pages I looked into:

Redirect POST htaccess

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

.htaccess redirect all sub-directories to file

Joe
  • 4,877
  • 5
  • 30
  • 51
Edson LC.
  • 25
  • 1
  • 7

1 Answers1

9

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.

To do this under Apache, update that last rule to end with

[QSA,L,R=307]

If you are only interested in the POST data, you don't even need the QSA flag.

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)

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.

madscientist159
  • 550
  • 4
  • 12