Redirect Post Htaccess

Is it possible to redirect post data?

Try this:

# redirect mail posting to index
RewriteRule send-mail index.php?send-mail [NC,P]

"P" acts like "L" in that it stops processing rules but it also tells the module that the request should be passed off to the proxy module intact (meaning POST data is preserved).

.htaccess redirect all POST request with data to a file

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.

How to redirect all POST requests via .htaccess?

...actually, after a certain number of tries I ended up with that code solution:

So, here's my post ajax which is made from any file in any project folder directing to the root folder or anyway:

$.post( "/" , { variable : "myVar" } );

In this case it goes to the mydomain.com but it actually does not, because it's halfway caught by .htaccess redirect like this:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^(.*)$ postManager.php [QSA,L=307]

postManager.php:

print_r($_POST);

And if I request response by .done(function(data){console.log(data)}); it gives it to me:

Array ( [variable] => Myvar )

Does anyone have any extra suggestions or comments regards to this code, because I'm not sure whether it's correct and safe, and whether it works exactly the way I decribed it..
Thanks in advance!

.htaccess redirect if request method is post

You've got the syntax from two entirely different, and competing modules there: mod_rewrite (RewriteCond) and mod_redirect (Redirect), as there's no connection between the two mod_redirect will always redirect, as there's no condition. Similarly you have a condition for a mod_rewrite redirection, but not the actual Redirection directive (RewriteRule). Anyway of the two modules use just use mod_rewrite eg.

RewriteCond %{REQUEST_METHOD} POST
RewriteRule /?gallery /wp-json/posts [L]

Apache 307 Redirect to redirect POST data

You can't match against querystring using a Redirec directive. You need to match against %{QUERY_STRING} variable using mod-rewrite. The following rule does what you want :

RewriteEngine on

RewriteCond %{QUERY_STRING} ^view=account&task=paypal$ [NC]
RewriteRule ^/?index\.php$ http://example.com/paypal/? [R=307,L]

? at the end of the destination url is important as it avoids appending old querystring to the new url.

Redirect POST htaccess

Your "add trailing slash" rule forces a header redirect:

 [R=301,L]

a header redirect will drop POST values.

You will have to drop that rule, or disable it for POST submissions:

# 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]


Related Topics



Leave a reply



Submit