POST request getting converted to GET when URL rew

2019-02-23 10:18发布

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.

2条回答
Animai°情兽
2楼-- · 2019-02-23 10:53

I had the same issue and checked a little more. This question is answered in another post:

redirectmatch changes post to get

查看更多
时光不老,我们不散
3楼-- · 2019-02-23 10:59

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.

查看更多
登录 后发表回答