如何在保留POST数据的同时重写URL? [英] How to rewrite a URL while keeping POST data?

查看:105
本文介绍了如何在保留POST数据的同时重写URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache及其代理设置通过HTTPS来提供网页(此处更多详细信息:解决方案

一如既往,问一遍,您将自己找到答案...

事实证明,它比我想象的要简单得多.只需告诉RewriteRule使用HTTP代码307就可以了.显然,这与其他重定向代码相同,但是307还保留POST数据.

对于那些想知道如何在Apache中执行此操作的人:

 RewriteRule ^/sprinklers$ /sprinklers/ [R=307]
 

就是这样,固定.

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?

解决方案

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.

这篇关于如何在保留POST数据的同时重写URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆