Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST request getting converted to GET when URL rewriting is done in apache httpd

I have an apache web server that acts as a reverse proxy to internal app servers. I have used ProxyPass and ProxyPassReverse to achieve this. I have multiple context roots mapping to different applications.

I am trying to remove the context root from the domain name for one context so that users can access the website directly as https://mydomain.com instead of https://mydomain.com/contextRoot. I have added the following rewrite rules instead of the proxypass and proxypassreverse configurations for this context.

# redirecting old URL to new URL
RewriteRule ^/contextRoot(.*)$ https://mydomain.com$1 [L,R=301]

# proxying to internal app servers
RewriteCond %{REQUEST_URI} !^(/anotherContextRoot1.*)$
RewriteCond %{REQUEST_URI} !^(/anotherContextRoot2.*)$
RewriteRule .* http://10.1.0.1:8080/contextRoot%{REQUEST_URI} [L,P]

This configuration works well for all http GET requests. For POST requests, the redirect happens, but the subsequent call becomes a GET.

Please help me understand why this happens and how can I correct this. I also want to understand is there any more rewrite rule configuration that I have add to do what proxypassreverse used to do in the previous configuration.

like image 909
Ganesh Ramachandran Nair Avatar asked Nov 04 '14 05:11

Ganesh Ramachandran Nair


1 Answers

This question is answered here https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect/99966#99966 - a short summary from this answer

In HTTP 1.1, there actually is a status code (307) which indicates that the request should be repeated using the same method and post data.

As others have said, there is a potential for misuse here which may be why many frameworks stick to 301 and 302 in their abstractions.

like image 136
Ganesh Ramachandran Nair Avatar answered Oct 15 '22 03:10

Ganesh Ramachandran Nair