Redirectmatch modifies the message to receive

I have two shared vhost. On www. one, I set this single line to .htaccess

redirectMatch 301 ^(.*)$ http://d_blur_blur_s.com$1 

Everything works as expected, except in the case where POST is converted to GET.
Please note that the message has parameters like get (I did not do this, and I will not change it). I'm just trying to avoid duplicate content. I am showing a Firebug track.

I expect the POST to be redirected to the main domain with a redirect or other trick.

firebug trace

Update
I have half of the internal links on the site written with www and the other half without it. Therefore, I need to keep both public, but not duplicate. I need GET sent as GET and POST files created as POST. the problem is big, I have 12,000 pages indexed and many forms. Therefore, at first I am looking for a universal solution without changing the code. I have full control of the server.

Thank you so much

+8
redirect .htaccess
source share
4 answers

Sending a response from your server for any request you make, regardless of whether it is a POST or GET request, always leads to the fact that your client makes a GET request (if you somehow do not allow it to NOT automatically follow the forwarding - sometimes I do it with curl, but I don’t know the widely used browsers with this functionality available to the user). The client browser takes the URL provided by the redirect, and treats it as the URL to execute the GET request. In no case will POST data be discarded by the server, since it is intended for the server resource at the source URL.

If you redirect beyond .htaccess, tell the PHP file to build the redirect response, the only option is to convert the POST parameters to the GET parameter string and add it to the end of the URL that you send back the client with the redirect response.

I am sure there is no way to make an automatic POST parameter that adds redirection in the .htaccess file or in the httpd.conf files, whether you use the redirection directive or the rewrite directive through the mod_rewrite module.

+6
source share

You redirect using 307 instead of 301 to save the message data, but some browsers show the user a dialog if he is sure that he wants to send the message data, so this is not realistic.

But I’d better go and fix the problem fundamentally. The only way to get a message in the wrong domain is if the html form belongs to the wrong domain (for example, <form action="www.d_blur_blur_s/public/main/loginGenerator.php" ... ). Just fix html.

Do not worry about duplicate content, as search engines never send post requests, but only receive. Your current decision should do the trick to prevent duplication of content.

+5
source share

The only way to redirect and save the POST data (what I know) is to use mod_rewrite with mod_proxy and then use the P flag in the RewriteRule.

On your www host, enable mod_rewrite, mod_rewrite and .htaccess via httpd.conf and then put this code in your .htaccess in the DOCUMENT_ROOT directory:

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^ http://d_blur_blur_s.com%{REQUEST_URI} [P] 
+2
source share

I came across this correspondence POST-> GET. The API call is as follows:

  curl -X POST https://example.com/api/user/123456789 

logged into my API framework using the GET request method.

The reason seems to be related to POST requests with an empty body. To avoid this problem, you can set the Content-Length header:

  curl -X POST https://example.com/api/user/123456789 -H 'Content-Length: 0' 

or pass something in the body:

  curl -X POST https://example.com/api/user/123456789 -d '' 
+2
source share

All Articles