Question

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

Was it helpful?

Solution

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top