且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过HTTP和HTTPS在页面之间进行通信/共享会话

更新时间:2023-08-18 16:27:04

最简单的答案是拥有所有链接到你的安全页面链接到 https:// 。显然,根据网站的不同,这可能有点噩梦。

The simplest answer is to have all links to your "secure" pages link to https://. Obviously this can be somewhat of a nightmare depending on the site.

另一种方法是设置URL重写规则,自动将安全页面定向到 https:// 如果尝试通过 http://

Another alternative is to set up URL rewrite rules to automatically direct secure pages to https:// if trying to access them via http://

访问它们,请查看 mod_rewrite 。根据您使用的Web服务器,可以使用其他选项来实现相同的功能,但这应该可以让您了解您的选项。我假设你使用的是PHP,你使用的是Apache,但情况并非如此?

Check out mod_rewrite for Apache if you are not familiar with the concept. Depending on what web server you are using there are other options available to achieve the same functionality, but that should give you an idea of what your options are. I assume since you're using PHP that you're using Apache, but could not be the case?

我想这可能是最常用的方法。如果所有安全页面都驻留在给定目录中,这使得它更容易,因为您可以编写规则来说明必须通过 https:// 请求该目录中的所有内容,否则 http :// 是合适的。

I would say that is probably the most common approach. If all of the secure pages reside in a given directory, that makes it even easier as you can write rules to say that everything in that directory must be requested via https://, otherwise http:// is suitable.