Forum Discussion
Rewrite URL on Request, and then Rewrite URL on response
Hi All,
We have several country specific urls tied to the same VIP. Our sever is designed to accept connection on an internal url (internalurl.com for the example below) and produce country specific content according to the added HTTP header (bla_site) I am trying to take a request for these urls, rewrite them to the internal URL with an added HTTP header that = the original url set as a variable ($header2). Once that has been processed by the server, rewirite the outgoing url back to the original URL the customer requested. I can get this to work with 1 url, but as soon as I introduce the variable, it doesn't seem to work.
Here is what I have so far:
when HTTP_REQUEST {
set header_host [string tolower [HTTP::host]]
HTTP::header insert bla_site $header2
HTTP::header replace Host internalurl.com
switch -glob [string tolower [HTTP::uri]] {
default { DEFAULT_POOL
pool pool_Default
}
}
}
when HTTP_RESPONSE {
if { [HTTP::is_redirect] }{
HTTP::header replace Location [string map [ list internalurl.com $header2 ] [HTTP::header Location]]
set location $header2
}
}
Hopefully this is descriptive enough to make sense. Thanks
7 Replies
- What_Lies_Bene1
Cirrostratus
You don't appear to be setting variable 'header2' anywhere. This should help;when HTTP_REQUEST { set header2 [string tolower [HTTP::host]] HTTP::header insert bla_site $header2 - WestonBlake_700
Nimbostratus
Thanks for noticing that. I changed the following line:
set header2 [string tolower [HTTP::host]]
It is still coming out of the F5 with the internalurl.com
- What_Lies_Bene1
Cirrostratus
Sorry do you mean in the request to the server or in the response? - WestonBlake_700
Nimbostratus
Sorry in the request, so now it looks like this:
when HTTP_REQUEST {
set header2 [string tolower [HTTP::host]]
HTTP::header insert bla_site $header2
HTTP::header replace Host internalurl.com
switch -glob [string tolower [HTTP::uri]] {
default { DEFAULT_POOL
pool pool_Default
}
}
}
when HTTP_RESPONSE {
if { [HTTP::is_redirect] }{
HTTP::header replace Location [string map [ list internalurl.com $header2 ] [HTTP::header Location]]
set location $header2
}
}
- What_Lies_Bene1
Cirrostratus
OK, so it looks good. How are you confirming it's not changed? A tcpdump would prove things one way or another. - WestonBlake_700
Nimbostratus
ok, Update, The above irule works like it should. I found an server in the mix that was stripping the headers. Thanks for the input. I guess I just needed a sanity check on my irule - What_Lies_Bene1
Cirrostratus
You're welcome. Glad it's sorted.
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