Forum Discussion
FMA
Nimbostratus
Mar 26, 2018Replace Host part in HTTP::Location
Hello, guys. I'm trying to find a way to perform manipulation with HTTP::header Location.
1. Web-browser requests https://abc.com
2. Web-server replies with HTTP/301 Location: https://xyz.com/{$URI} (URI part might change when browsing)
3. I need to have HTTP::Location modified to https://abc.com/{$URI} (whatever was put in 2)
I was trying to achieve this with getfield with "/" as delimiter to catch URI part, but this gets broken as number of slashes in Location might increase 😕
Thanks!
- Lee_Sutcliffe
Nacreous
You could try something like this:
when HTTP_REQUEST { set uri [HTTP::uri] } when HTTP_RESPONSE { if {([HTTP::is_redirect]) && ([HTTP::header Location] contains "xyz.com" )} { HTTP::header replace Location "https://abc.com$uri" } }
- Stanislas_Piro2
Cumulonimbus
Hi,
I recommend to replace absolute URI to relative URI. This rewrite rule may have been useless if the server had responded with relative URI.
when HTTP_RESPONSE { if { [HTTP::header exists Location] && ([URI::host [HTTP::header value Location]] equals "xyz.com")} { HTTP::header replace Location [string map {https://xyz.com/ /} [HTTP::header value Location]] } }
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