Forum Discussion
Rewriting multiple values of HTTP Location header
Hello Frédéric, do you need a redirect from first URL to second URL?
Will the two URLs always be the same or is there a whole subfolder content to be redirected?
In first case, in my opinion a LTM policy configured for static redirect will just work fine.
In second case, there's a few ways to do it depending on the requirements.
If there's a big list of URLs to be handled, you might want to work with Data Groups to keep it simple. Configure a string-type DG like this:
ltm data-group internal /Common/datagroup_path_rewrite {
records {
/oldsubfolder1/ { }
/oldsubfolder2/ { }
/oldsubfolder3/ { }
/oldsubfolder4/ { }
/oldsubfolder5/ { }
}
type string
}
Then use it in an iRule for path replacement
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] eq "myorighost:81" } {
HTTP::header replace Host "myrewritedhost"
# this is not a redirect
}
# read as: does the uri contain an element of datagroup_path_rewrite (case sensitive)
if {[class match [HTTP::uri] contains datagroup_path_rewrite]} {
HTTP::path /analytics/Portal/jsp/html/portal/portal.js
# this rewrites the URI path before senting traffic to BE server
}
}
Also, I've recently answered a similar question in this thread, see if this helps as well.
- Lemaire_FrédériJan 31, 2022
Altostratus
Hello,
Thanks for your answer.
In fact, I need to replace a reverse proxy with the F5, currently with LTM.The problem I'm having is the rewriting of the RESPONSE and specifically the Location Header.
For the HTTP request rewriting I was able to rewrite it with "internalhost" and internal uri/path to the back-end webserver.The problem I'm having in the Response redirects coming from the back-end that I need to rewrite with external host + adapt some path and query params ( within the same redirect location )
How can I do that ?
for exemple :
Http location received from the back-end that need to be rewrited tohttp://internalhost/SASPortal/public http://ExternalHost/analytics/Portal/public
http://internalhost/SASPortal/test?myparam=http%3ASASPortal... http://internalhost/SASPortal/test?myparam=http%3%2F%2Fanalytics%2FPortal...
http://internalhost/SASTheme/mytheme http://ExternalHost/Theme_extranal/mytheme
I also need to rewrite the referer with the external uri and some relative path in the location
For the Content rewriting of the response, I 'm using a stream profile and this is ok . But I'm having a lot of problems with the rewriting of the Location header.
many thanks in advance for your future answers.Regards
Frédéric
- Jan 31, 2022
Hi Frédéric,
Can you add default stream profile to vs and try this iRule?
when HTTP_REQUEST { STREAM::disable if { [HTTP::host] eq "externalhost" } { HTTP::host "internalhost" switch -glob [HTTP::uri] { "/analytics/Portal*" { HTTP::uri [string map {"/analytics/Portal" "/SASPortal"} [HTTP::uri]] } "/Theme_extranal*" { HTTP::uri [string map {"/Theme_extranal" "/SASTheme"} [HTTP::uri]] } } } } when HTTP_RESPONSE { if { [HTTP::header exists "Location"] } { HTTP::header replace Location [string map [list "internalhost" "externalhost" "/SASPortal" "/analytics/Portal" "/SASTheme" "/Theme_extranal" "/valuefrominternal/" "/valuetoexternal/"] [URI::decode [HTTP::header Location]]] } STREAM::expression {@internalhost@externalhost@} STREAM::enable }
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