Hi Bigipjr28,
below are the requested iRules. I do think that the DataGroup approach is more suited for less TCL/iRule experienced administrators, since the daily administration would be GUI based.
iRule1: Using DataGroups selection with added logging
when HTTP_REQUEST {
if { [set temp(virtual) [URI::basename [virtual name]]] starts_with "DC_" } then {
if { [set temp(host) [class match -value $temp(virtual) equals DG_VIRTUAL_2_HOST]] ne "" } then {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(host)\""
HTTP::header remove Host
HTTP::header insert Host $temp(host)
} else {
The Datagroup doesn't have a match.
Add additional code here to handle those exeptions or simply let the requests pass.
}
} else {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(virtual)\""
HTTP::header remove Host
HTTP::header insert Host $temp(virtual)
}
unset -nocomplain temp
}
Note: The DataGroup is TYPE=STRING, KEY=YOUR_VIRTUAL_NAME, Value=www.your-site.de
iRule2: Using SWITCH selection with added logging
when HTTP_REQUEST {
switch -glob -- [URI::basename [virtual name]]] "DC_Virtual_1" {
set temp(host) "www.domain1.de"
} "DC_Virtual_2" {
set temp(host) "www.domain2.de"
} "DC_Virtual_3" {
set temp(host) "www.domain3.de"
} "DC_Virtual_4" {
set temp(host) "www.domain4.de"
} "DC_Virtual_5" {
set temp(host) "www.domain5.de"
} "DC_Virtual_6" {
set temp(host) "www.domain6.de"
} "DC_Virtual_7" {
set temp(host) "www.domain7.de"
} "DC_Virtual_8" {
set temp(host) "www.domain8.de"
} "DC_Virtual_9" {
set temp(host) "www.domain9.de"
} "DC_Virtual_10" {
set temp(host) "www.domain10.de"
} "DC_*" {
The Datagroup doesn't have a match.
Add additional code here to handle those exeptions or simply let the requests pass.
} default {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(virtual)\""
HTTP::header remove Host
HTTP::header insert Host $temp(virtual)
unset -nocomplain temp
return
}
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(host)\""
HTTP::header remove Host
HTTP::header insert Host $temp(host)
unset -nocomplain temp
}
Additional Note: If you dont have clean naming convention for your Virtual Servers, then you may want to use the iRules below. Those would lookup well known Virtual Server using the DataGroup/Switch command and if this fails it would use the Virtual Server name as the new host name. But the logic is overall more error prone...
iRule1
when HTTP_REQUEST {
if { [set temp(host) [class match -value [set temp(virtual) [URI::basename [virtual name]]] equals DG_VIRTUAL_2_HOST]] ne "" } then {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(host)\""
HTTP::header remove Host
HTTP::header insert Host $temp(host)
} else {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(virtual)\""
HTTP::header remove Host
HTTP::header insert Host $temp(virtual)
}
unset -nocomplain temp
}
iRule2
when HTTP_REQUEST {
switch -glob -- [set temp(virtual) [URI::basename [virtual name]]] "DC_Virtual_1" {
set temp(host) "www.domain1.de"
} "DC_Virtual_2" {
set temp(host) "www.domain2.de"
} "DC_Virtual_3" {
set temp(host) "www.domain3.de"
} "DC_Virtual_4" {
set temp(host) "www.domain4.de"
} "DC_Virtual_5" {
set temp(host) "www.domain5.de"
} "DC_Virtual_6" {
set temp(host) "www.domain6.de"
} "DC_Virtual_7" {
set temp(host) "www.domain7.de"
} "DC_Virtual_8" {
set temp(host) "www.domain8.de"
} "DC_Virtual_9" {
set temp(host) "www.domain9.de"
} "DC_Virtual_10" {
set temp(host) "www.domain10.de"
} default {
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(virtual)\""
HTTP::header remove Host
HTTP::header insert Host $temp(virtual)
unset -nocomplain temp
return
}
log -noname local0.debug "Request on Virtual \"[virtual name]\" for Host \"[HTTP::header value Host]\" changed to Host \"$temp(host)\""
HTTP::header remove Host
HTTP::header insert Host $temp(host)
unset -nocomplain temp
}
Cheers, Kai