Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect with modified Host and URI from variable

H_Y
Nimbostratus
Nimbostratus

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 1

Samir
MVP
MVP

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