gab
gab

Reputation: 77

Why POST don't work with some rewrite conditions in htaccess?

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?

Upvotes: 1

Views: 348

Answers (1)

M. Eriksson
M. Eriksson

Reputation: 13635

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.

Upvotes: 2

Related Questions