0

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

Gumbo
  • 643,351
  • 109
  • 780
  • 844
stubotnik
  • 1,952
  • 2
  • 17
  • 31

1 Answers1

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]
TonyCool
  • 1,004
  • 1
  • 6
  • 5
  • Thanks man - that does indeed work! I was hoping there was a way to run that domain check a single time, rather than before each rule - otherwise my .htaccess file is going to become quite bloated! Maybe that's hoping for too much... – stubotnik Jul 15 '09 at 11:14
  • If you put these rules into .htaccess in the root of secure.example.com, you can omit the host check at all. – TonyCool Jul 16 '09 at 06:48
  • I hear you - unfortunately I'm currently restricted to using the same .htaccess file on the secure and www domains. Marking this as the answer - thanks for the help! – stubotnik Jul 16 '09 at 09:25