Redirect POST htaccess

This question is very similar to: Is it possible to redirect post data? (asked caretaker), but this answer does not seem to work for me.

I have a form:

<form action="http://a.test.com/contact" name="contact" method="post"> 

and inside the additional domain (test.com is an addon), there is a subdomain (a.), and inside there I have the item.php and .htaccess file

my htaccess looks like this:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^/]+)/$ $1.php # Forces a trailing slash to be added RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] #normal rewrites RewriteRule ^[~|-]?([a-zA-Z0-9]+)[/]*$ item.php?user=$1 [NC,L] 

note: I left it as [NC, L], because when I changed it to [NC, P], it gave me a 500 server error.

and my item.php

 <?php echo "<pre>"; print_r($_POST); echo "</pre>"; 

and no matter what the form contains, $ _POST is empty ... however, if I do http://a.test.com/item.php?user=contact as an action.

everything goes well. POSTing skips htaccess and the SO solution does not work.

Thanks in advance

+7
source share
1 answer

The "add trailing slash" rule forces the header to be redirected:

  [R=301,L] 

redirecting the header will reset the POST values.

You will have to reject this rule or disable it to send a POST:

 # Forces a trailing slash to be added RewriteCond %{REQUEST_METHOD} !=POST RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] 
+17
source

All Articles