Forum Discussion
sandy16
Altostratus
Dec 03, 2014Irule help for host header redirection
Hi experts, I need to write an irule which will redirect some different host headers/urls to one single-different url. After doing some digging around on devcentral i found this one should do the job...
shaggy
Nimbostratus
Dec 03, 2014if it's a list of hostnames that isn't too large and won't be changing too often, i would just use some or's:
when HTTP_REQUEST {
if {([string tolower [HTTP::host]] equals "www.example.com") or ([string tolower [HTTP::host]] equals "abccorp.com" or [string tolower [HTTP::host]] equals "xyzmedia.ca")} {
HTTP::redirect "https://mywebsite.com"
}
}
if you want the irule to be more flexible and extensible in regards to adding hostnames, you should use a data group. create data-group (reference in irule below as hostname-data-group) with a list of the hostnames you want redirected, and use an irule similar to:
when HTTP_REQUEST {
if { class match [string tolower [HTTP::host]] equals hostname-data-group } {
HTTP::redirect "https://mywebsite.com"
}
}
- sandy16Dec 03, 2014
Altostratus
Thanks Shaggy.
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