iRule Multiple site redirect

How do I write an iRule that redirects multiple sites.

Site 1) aaa.com redirects to www.bbb.com/ccc/ddd

Site 2) eee.com redirects to www.bbb.com/fff

Site 3) ggg.com redirects to www.bbb.com/hhh

I thought it should look like this but it’s not right.

when HTTP_REQUEST {

if { [string tolower [HTTP::host]] contains “aaa.com” } {

HTTP::header replace “Host” “www.bbb.com”

HTTP::uri “/ccc/ddd[HTTP::uri]”

} {

if { [string tolower [HTTP::host]] contains “eee.com” } {

HTTP::header replace “Host” “www.bbb.com”

HTTP::uri “/fff[HTTP::uri]”

} {

if { [string tolower [HTTP::host]] contains “ggg.com” } {

HTTP::header replace “Host” “www.bbb.com”

HTTP::uri “/hhh[HTTP::uri]”

}

Hi rwagner1,

If you want to change url in browser:

when HTTP_REQUEST {
	switch [HTTP::host] {
		"aaa.com" {
			HTTP::redirect "http(s)://www.bbb.com/ccc/ddd"
		}
		"eee.com" {
			HTTP::redirect "http(s)://www.bbb.com/fff"
		}
		"ggg.com" {
			HTTP::redirect "http(s)://www.bbb.com/hhh"
		}
	}
}

If you don’t want to change url in browser:

when HTTP_REQUEST {
	switch [HTTP::host] {
		"aaa.com" {
			HTTP::header replace "Host" "www.bbb.com"
			HTTP::uri "/ccc/ddd"
			pool pool_www.bbb.com
		}
		"eee.com" {
			HTTP::header replace "Host" "www.bbb.com"
			HTTP::uri "/fff"
			pool pool_www.bbb.com
		}
		"ggg.com" {
			HTTP::header replace "Host" "www.bbb.com"
			HTTP::uri "/hhh"
			pool pool_www.bbb.com
		}
	}
}