Forum Discussion

VJ_96387's avatar
VJ_96387
Icon for Nimbostratus rankNimbostratus
Feb 18, 2010

HTTP to HTTPS REDIRECTION VIA IRULES

We have 2 pairs of LTM (one internet facing) and one in DMZ. I n...

 

 

Contributed by: VijayRangarajan - vjrangarajan at gmail.com

 

Description

 

Hi All,

 

 

We have 2 pairs of LTM (one internet facing) and one in DMZ. I need a peculiar request to implement for one of the VIP.

 

 

I am unable to get this working and have been racking my brains. Please help!!!

 

 

 

Current Setup

 

 

we have a VS abc.com which is accessed from Internet. This Vs is asscoiated with IRULE1 (refer below)

 

 

The internal load balancer has IRULE 2 attached to the VS abc.corp.

 

 

Te requirement is whenever the user access the url http://abc.com (from internet) this must redirect via the internal load balancer to https://abc.com/irj/portal using the internal VS abc.corp

 

 

Please let me know, if you need further clarifications?

 

 

Your speedy response is apprecaited!!!!

 

 

Regards,

 

 

Vijay Rangarajan

 

 

iRule Source

 

IRULE 1:

 

 

when HTTP_REQUEST {

 

set P [TCP::local_port]

 

set H [HTTP::host]

 

set U [HTTP::uri]

 

set X "FALSE"

 

set I [IP::remote_addr]

 

 

- Redirect if using port 80 -

 

 

if {$P equals"80"}{

 

set X "TRUE"

 

}

 

log "A: IP=$I H=$H U=$U P=$P Redirect=$X"

 

 

- Redirect to .corp if from inside-

 

if {$I equals "internet facing public IP" \

 

and [string match -nocase "*abc.com" $H]}{

 

regsub -nocase {abc.com} $H {abc.corp} R

 

set H "$R"

 

set X "TRUE"

 

}

 

log "B: IP=$I H=$H U=$U P=$P Redirect=$X"

 

 

- Redirects just for ESS websites -

 

if {[string equal "/" $U] and \

 

[string match "employees*" $H]}{

 

set U "/irj/"

 

set X "TRUE"

 

}

 

log "C: IP=$I H=$H U=$U P=$P Redirect=$X"

 

 

- Execute redirect if necessary -

 

 

if {[string equal "TRUE" $X]}{

 

log "I=$I H=$H U=$U Redirect to https://$H$U"

 

HTTP::redirect "https://$H$U"

 

}

 

}

 

 

IRULE 2:

 

 

when HTTP_REQUEST {

 

set H [HTTP::host]

 

set U [HTTP::uri]

 

if {[regexp {.abc..corp$} $H]} {

 

set H "$H.abc.corp"

 

}

 

if {[string equal "/" $U] and [string match "employees*" $H]}{

 

set U "/irj/"

 

}

 

HTTP::redirect "https://$H$U"

 

}