Forum Discussion
Goran_Blomquis1
Nimbostratus
May 29, 2008rewrite host in redirect
Hi Devcentral and all users.
I have a case where I need to rewrite host in 302 redirect. It´s work fine but theres a lot of hosts behind the F5 and they need to keep hostname intact (not using hostname on VIP in redirect). My question are quite short. Is it possible to use woildcard in string command? So I rewrite to one host in location header, but keep URI in Location in the redirect? (I tried to pars host HTTP request and use that host in redirect and keep URI in location header but i faild).
So insted of
when HTTP_RESPONSE {
if { [HTTP::is_redirect] }{
HTTP::header replace Location "[string map {"A.internal.com" "X.external.com"} [HTTP::header Location]]"
}
}
I nedd to do somthing like
when HTTP_RESPONSE {
if { [HTTP::is_redirect] }{
HTTP::header replace Location "[string map {"*.*.*" "X.external.com"} [HTTP::header Location]]"
}
}
Is that possible?
Have a great day
Sunny hellos from Sweden
5 Replies
- hoolio
Cirrostratus
Hi,
I can't think of a simple way to do this with string-based commands. Here is an option for using a regex:
HTTP::header replace Location [regsub -nocase {/[a-z]*\.[a-z]*\.[a-z]*/} [HTTP::header Location] /x.external.com/]
Note that the leading and trailing forward slashes are literal and are just used to anchor the match to just the host value.
Aaron - hoolio
Cirrostratus
The regsub will replace /*.*.*/ with /x.external.com/ in the Location header value, so yes, the URI will be preserved.
Here's a demonstration:
% regsub -nocase {/[a-z]*\.[a-z]*\.[a-z]*/} https://my.site.com/path/to/file.ext?param=val /my.new.host/
https://my.new.host/path/to/file.ext?param=val
Aaron - Goran_Blomquis1
Nimbostratus
Great!
Thank you Aron, I try it out.
I also think it should work with
HTTP::header replace Location [regsub -nocase {http://.*?/} [HTTP::header Location] http://x5044.nisse.com/]
(if ? are supported to match just the first slash and not the following slash)
I add a new comment when I have tested it
/Göran Blomquist - hoolio
Cirrostratus
http://.*?/ would indeed only match up to and including the first forward slash after the http://. I thought you only wanted to perform the replacement if there was a domain in the format of subdomain.domain.tld.
Aaron - Goran_Blomquis1
Nimbostratus
Thanks for all help.
Works perfect! final I-rule looks somthing like
rule rewrite_301_test {
when HTTP_RESPONSE {
if {[HTTP::is_redirect]}{HTTP::header replace Location [regsub -nocase {\/\/.*?/}
[HTTP::header Location] "f5vip.test.local/"]
}
}
Have a great day
Goran
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
