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

不羁的心 提交于 2019-12-04 03:26:54

问题


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.


回答1:


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.




回答2:


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

redirectmatch changes post to get



来源:https://stackoverflow.com/questions/26728231/post-request-getting-converted-to-get-when-url-rewriting-is-done-in-apache-httpd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!