Isapi Rewrite - 在负载均衡器后面的重定向中保留 HTTPS

发布于 2024-07-27 05:24:00 字数 1095 浏览 4 评论 0原文

我正在运行一个具有 2 个独立子域的网站 - 一个用于 HTTP,另一个用于 HTTPS。

  • http://www.example.com
  • https://secure.example.com

http://secure.example.com 没有存在且不会解决。

问题在于该站点在处理所有 SSL 的负载平衡器后面运行。 负载均衡器和 Web 服务器之间始终使用 HTTP 进行通信。

因此,当使用 Isapi Rewrite 3(IIS 的 mod_rewrite 克隆)来实现某些重定向时,我遇到了问题。

就 Isapi Rewrite 而言,HTTPS 已关闭 - 因此 secure.example.com 上的重定向失败。

假设我有一条规则:

RewriteRule ^/example/$ /test/ [R=301,L]

如果我向 https://secure.example.com/example/ 发出请求,我希望最终得到 https://secure.example.com/test/ 但是,由于 Isapi Rewrite 将 HTTPS 视为关闭,我最终会访问 http://secure.example .com/test/

如果域名是 secure.example.com,有什么方法可以强制重定向到 HTTPS?

类似的事情是:

RewriteCond %{SERVER_NAME} secure.example.com
RewriteRule ^/(.*)$ https://secure.example.com/$1

除了不起作用 - 它立即强制显式重定向,而我想继续处理其他RewriteRules

谢谢,

斯图

I'm running a site which has 2 separate sub-domains - one for HTTP and another for HTTPS.

  • http://www.example.com
  • https://secure.example.com

http://secure.example.com does not exist and will not resolve.

The problem is that the site is running behind a load balancer which handles all SSL. Communication between the load balancer and the web servers in always HTTP.

So, when using Isapi Rewrite 3 (a mod_rewrite clone for IIS) to implement some redirects I'm running into a problem.

As far as Isapi Rewrite is concerned HTTPS is turned off - so redirects on secure.example.com are failing.

Say I have a rule which says:

RewriteRule ^/example/$ /test/ [R=301,L]

If I make a request for https://secure.example.com/example/ I would like to end up on https://secure.example.com/test/ but, because Isapi Rewrite sees HTTPS as OFF, I end up on http://secure.example.com/test/.

Is there any way I can force redirects to be to HTTPS if the domain is secure.example.com?

Something along the lines of this:

RewriteCond %{SERVER_NAME} secure.example.com
RewriteRule ^/(.*)$ https://secure.example.com/$1

Except that doesn't work - it immediately forces an explicit redirect, whereas I want to continue processing other RewriteRules.

Thanks,

Stu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-08-03 05:24:00

像这样怎么样:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.mydomain\.com$ [NC]
RewriteRule ^/example/$ https://secure.mydomain.com/test/ [R=301,L]

How about smth like this:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.mydomain\.com$ [NC]
RewriteRule ^/example/$ https://secure.mydomain.com/test/ [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文