1

All $_POST do not work with this .htaccess code in place:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

// ========================== this code too is in place, but it seems not to impact on $_POST
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
// =================================================

Any idea on why such a problem? What can I do to solve and get the same result for php extensions?

gab
  • 77
  • 1
  • 1
  • 9
  • 2
    `R=301` is a redirect. If you send a POST request to that URL, the web server will redirect the request (using GET) to the new URL and all posted data will be removed (since GET requests doesn't support anything in the body of the request). The second rule is a rewrite, which isn't the same thing as a redirect. You can more about the differences here: https://stackoverflow.com/a/12399668/2453432 – M. Eriksson Jul 29 '20 at 11:24
  • 1
    You can try to use `R=308` instead. That's also a permanent redirect, but it tells the client to use the same http method. Not sure how widely used/implemented it is though. – M. Eriksson Jul 29 '20 at 11:31
  • @Magnus - Your suggestion works. But about what you said, would you expect any "collateral effect"? – gab Jul 29 '20 at 11:40
  • No, not really. If someone has issues with it, it's mostly poorly written clients that doesn't follow the standards and to be honest, we shouldn't care about those. – M. Eriksson Jul 29 '20 at 11:42
  • Given that, I agree. Thank you, so – gab Jul 29 '20 at 11:51
  • 1
    @MagnusEriksson You should add that as an answer. In addition, the OP shouldn't be sending POST requests to the non-canonical URL to begin with. (A 308 is widely supported.) – MrWhite Jul 29 '20 at 11:52

1 Answers1

2

R=301 is a redirect. If you send a POST request to that URL, the web server will redirect the request (using GET) to the new URL and all posted data will be removed (since GET requests doesn't support anything in the body of the request).

The second rule is a rewrite, which isn't the same thing as a redirect.

You can more about the differences here: https://stackoverflow.com/a/12399668/2453432

Solution

Use R=308 instead. That is also a permanent redirect but it tells the client to use the same http method for the new request.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40