Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite HTTP GET request to POST in Apache using htaccess

I need to change a behavior of third party PHP application and to revert changes back shortly after that. If I could rewrite GET requests and make POST ones out of them, I would save a lot of time and could avoid making any changes in the application.

Is it possible to transform GET http://website/action1?param=1 into POST http://website/action2, with param being part of post request, using .htaccess?

Although, I can redirect the first GET request to a new page which will do POST to the second URL automatically (Javascript), I want to keep number of browser-server interactions as low as possible.

like image 556
Andy Avatar asked Aug 17 '12 16:08

Andy


People also ask

What is rewrite base in htaccess?

mod_rewrite. The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.

How can I redirect and rewrite my URLs with an .htaccess file?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

What is rewrite rule in Apache?

RewriteRule specifies the directive. pattern is a regular expression that matches the desired string from the URL, which is what the viewer types in the browser. substitution is the path to the actual URL, i.e. the path of the file Apache servers. flags are optional parameters that can modify how the rule works.


1 Answers

Is it possible to transform GET http://website/action1?param=1 into POST http://website/action2, with param being part of post request, using .htaccess?

No, this isn't possible. A GET and a POST are entirely different requests, with different request headers and different responses. The rewrite engine only affects the URI and can't change the actual request. You're going to have to rely on Javascript on the browser's end.

like image 183
Jon Lin Avatar answered Oct 17 '22 15:10

Jon Lin