问题
I'm using Apache and its proxy settings to serve a web page over HTTPS (more detail here: click).
In the previous question, I was struggling with why the POST data was disappearing between my browser and my server. Now I know that it was caused by using Apache's RewriteRule
. So I tried working around that with proxies, but this resulted in the web page sending out all other requests on the main domain, instead of the sub domain it's at. For example: My main web page is at myUrl.com/sprinklers
. This goes through a proxy, which goes to localhost:8091
. The main HTML page loads, but ALL other calls it makes, it makes at myUrl.com/any/path/it/needs
, while it should be at myUrl.com/sprinklers/any/path/it/needs
.
Sadly, I'm stuck in the middle:
- Using
RewriteRule
means that everything works, but I lose the POST data, which I need. - Using proxies means that the POST data works, but also that I get a ton of 404's, because the web page somehow now expects things to be at the root of the domain, instead of the subdomain it's at.
The trailing slash needs to be there, since without it, the same happens as when I use proxies, I get a ton of 404's for all bits and pieces of the web page.
I tried using ProxyHTMLURLMap in all shapes and forms (all found online), but none worked.
TL;DR:
I need to enable two-way traffic between myUrl.com/sprinklers/.*
and localhost:port/.*
, while also retaining POST data. How do I do that?
回答1:
As always, ask and you shall find the answer yourself...
It turned out to be a lot simpler than I imagined. Simply telling RewriteRule
to use HTTP code 307 did the trick. Apparently, this is the same as the other redirection codes, but 307 also keeps the POST data.
For those wondering how to do this in Apache:
RewriteRule ^/sprinklers$ /sprinklers/ [R=307]
That's it, fixed.
来源:https://stackoverflow.com/questions/56976761/how-to-rewrite-a-url-while-keeping-post-data