Forum Discussion
LeonK_146224
Nimbostratus
Mar 04, 2014http domain redirect
Hi Guys,
new to irules so need your help on how to re-write the irule to include more descriptive strings.
1:
We have a simple http redirect rule that we are using that utilizes datagroup strings: ...
Kevin_Stewart
Employee
Mar 05, 2014I think the general problem you're having is that you're trying to redirect on URI but only evaluating the host value. I see three possible options here:
-
Create two separate data groups - one for URI paths and one for host values
ltm data-group internal myhosts { records { domain1.de { data domain.com } domain2.de { data domain.com } } type string } ltm data-group internal myuris { records { / { data /de-de } /careers { data /de-de/careers } } type string } when HTTP_REQUEST { set myhost [class match -value [string tolower [HTTP::host]] equals myhosts] set myuri [class match -value [string tolower [HTTP::uri]] starts_with myuris] set redirect 0 if { $myhost ne "" } { set redirect 1 } else { set myhost [HTTP::host] } if { $myuri ne "" } { set redirect 1 } else { set myuri [HTTP::uri] } if { $redirect } { HTTP::redirect "http://${myhost}${myuri}" } } -
Create a single data group that incorporates host and URI
ltm data-group internal mypaths { records { domain1.de/ { data domain.com/de-de } domain1.de/careers { data domain.com/de-de/careers } } type string } when HTTP_REQUEST { set mypath [class match -value [string tolower [HTTP::host][HTTP::uri]] starts_with mypaths] if { $mypath ne "" } { HTTP::redirect "http://$mypath" } } -
Assuming the host is only going to change between a very small set of values, just build a data group for URIs
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "domain1.de" - "domain2.de" { HTTP::redirect "http://domain.com[HTTP::uri]" } } set myuri [class match -value [string tolower [HTTP::uri]] starts_with myuris] if { $myuri ne "" } { HTTP::redirect "http://[HTTP::host]${myuri}" } }
Arguably I think the third option would be the easiest to manage, with option 2 being the most difficult.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects