Isapi Rewrite - preserving HTTPS in redirects behind load balancer

别来无恙 提交于 2019-12-11 14:53:30

问题


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


回答1:


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]


来源:https://stackoverflow.com/questions/1130445/isapi-rewrite-preserving-https-in-redirects-behind-load-balancer

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