Forum Discussion

H_Y's avatar
H_Y
Icon for Nimbostratus rankNimbostratus
Jun 25, 2020

Redirect with modified Host and URI from variable

Hello, I am very new to iRules and facing an issue while trying to redirect based on the below scenario.

 

Trying to achieve HTTPS://mydomain1.com/"clientname" to HTTPS://demo-"clientname".mydomain2.com/"clientname"

Tried below iRule but it is not redirecting, it stays on initial request in browser.

 

when HTTP_REQUEST {

if { [class match [string tolower [getfield [HTTP::uri] "/" 2]] equals clientnames_dg] } {

set clientname [getfield [HTTP::uri] "/" 2] } {

HTTP::respond 301 "Location" "https://demo-${clientname}.mydomain2.com/demo-${clientname}"

}

}

1 Reply

  • Some correction needed in iRule. Go with this..

    when HTTP_REQUEST {
    	set clientname [string tolower[getfield [HTTP::uri] "/" 2]]
    if { [class match [string tolower[getfield [HTTP::uri] "/" 2]] equals clientnames_dg] } {
    HTTP::respond 301 Location "https://demo-$clientname.mydomain2.com/$clientname"
    	}
    }

    Thanks