Forum Discussion
Rewriting host and part of URI, then appending the remainder of the URI
Trying to create an iRule to bail out my Application people. I need to modify the existing host to be a new host, then modify the "starts_with" portion of the URI, but also append the remainder of the URI for the end-user.
So, http://Server1/ThisURI/end-up-here.htm should rewrite to http://FinalDestination/new/end-up-here.htm
I've architected the following iRule that's not currently working:
when HTTP_REQUEST {
if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and
([HTTP::uri] starts_with "/ThisURI") } {
HTTP::header replace Host "FinalDestination"
HTTP::uri "/new[string range $uri 8 end]"
}
}
Any help would be much appreciated.
Thanks.
Joe
3 Replies
- nathe
Cirrocumulus
Joe
Do you need to set the uri variable first?
when HTTP_REQUEST {
set uri [HTTP::uri]
......etc
Rgds
N - Joe_Erchul_4263
Nimbostratus
Nathan,
Thanks for the tip. I added the variables as follows, but still no luck. I don't use variable definition much, so could you check my format for the correct syntax?
Thanks.
Joe
when HTTP_REQUEST {
set uri [HTTP::uri]
set header [HTTP::host]
if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and
([HTTP::uri] starts_with "/ThisURI") } {
HTTP::header replace Host "FinalDestination"
HTTP::uri "/new[string range $uri 8 end]"
}
} - nathe
Cirrocumulus
Joe
Without my test bed to double check things do look correct. Here's my iRule with a slight amendment to rule out case insensitivities:
when HTTP_REQUEST {
switch [string tolower [HTTP::uri]] {
set uri [HTTP::uri]
if { (([HTTP::host] equals "Server1") or ([HTTP::host] equals "Server2")) and
($uri starts_with "/ThisURI") } {
HTTP::header replace Host "FinalDestination"
HTTP::uri "/new[string range $uri 8 end]"
}
}
}
What happens if you do a curl -i http://Server1/ThisURI/end-up-here.htm -what response do you get back?
N
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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