Forum Discussion
barry_8239
Nimbostratus
Nov 30, 2012irule http redirect help
Hi All, i am fairly new to F5 world and need some assistance in redirecting a url. I've tried the following, but the browser will still show http://example/test and not the new url http://newserver/test. Any helpo is much appreciated.
when HTTP_REQUEST {
if{ [HTTP::host] contains "example/test"} {
HTTP::redirect http://newserver/test[HTTP::uri]
}
}
9 Replies
- What_Lies_Bene1
Cirrostratus
Try this;when HTTP_REQUEST { if { [HTTP::host] contains "example/test" } { HTTP::redirect "http://newserver/test[HTTP::uri]" } } - What_Lies_Bene1
Cirrostratus
I'm not sure why you're adding the old URI to the new, this might work better;when HTTP_REQUEST { if { [HTTP::host] contains "example" } { HTTP::redirect "http://newserver[HTTP::uri]" } } - What_Lies_Bene1
Cirrostratus
I'm not sure why you're adding the old URI to the new, this might work better;when HTTP_REQUEST { if { [HTTP::host] contains "example" } { HTTP::redirect "http://newserver[HTTP::uri]" } } - barry_8239
Nimbostratus
You are the best!! That was it! Thank you very much. Redirect works like a charm.
Thanks again
- barry_8239
Nimbostratus
I have it halfway working now. IS there a way to add another host name to the above irule?
The redirect works when entering example in the browser, but i also need to add "sample" as well. Would the following work? When i put sample in the url i get an iis page and not redirected to newserver.
when HTTP_REQUEST {
if { [HTTP::host] contains "example" or "sample" } {
HTTP::redirect "http://newserver[HTTP::uri]"
}
}
when HTTP_REQUEST {
if { [HTTP::host] contains "example" or "sample" } {
HTTP::redirect "http://newserver[HTTP::uri]"
}
} - What_Lies_Bene1
Cirrostratus
Sure, try this;when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "example*" - "sample" { HTTP::redirect "https://otherserver.com[HTTP::uri]" } } - barry_8239
Nimbostratus
i get all sort of parameter errors when i do an update after adding the rule - barry_8239
Nimbostratus
This is what i tried to add
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"example*" -
"sample" {
HTTP::redirect "http://newserver[HTTP::uri]"
}
} - What_Lies_Bene1
Cirrostratus
Sorry, missing the last bracket;when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "example*" - "sample" { HTTP::redirect "https://otherserver.com[HTTP::uri]" } } }
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