Forum Discussion
URL/URI rewrite without changing in Client browser
- Oct 06, 2022
I'd maybe argue that partitions aren't create separate logical BIG-IPs. It's more about building separate administrative domains on a single BIG-IP. Further, partitions can always access the /Common partition. To answer your question though, it depends on the level of isolation, but you should simply be able to point to the VIP in the oter partition,
virtual "/abc-app-dev/np-api-vip" or virtual "/Common/abc-app-dev/np-api-vip"
You don't need SNAT to communicate between VIPs on the same BIG-IP.
- Dec 08, 2022
Hi Kevin,
Thanks for your guidance. Here is what I figured out and it is working now. All happened due to your idea so thanks again.
IRule for same routing domain :-
when HTTP_REQUEST {
log local0. "Incoming request: [HTTP::host]:[HTTP::uri]"
if { [set match [class match -value -- "[HTTP::host]:[HTTP::uri]" starts_with datagroup_Name]] ne "" } {
log local0. "Datagroup match: $match"
## Get first URI path in client request
set FIRSTPATH [getfield [HTTP::path] "/" 2]
## Split match into host and path
set matchlist [split $match ":"]
set MATCHHOST [lindex $matchlist 0]
set MATCHPATH [lindex $matchlist 1]
## Replace FIRSTPATH with MATCHPATH (from full HTTP::uri)
set UPDATEDPATH [string map [list "/$FIRSTPATH" "$MATCHPATH"] [HTTP::uri]]
log local0. "Updated host: $MATCHHOST"
log local0. "Updated path: $UPDATEDPATH"
HTTP::host $MATCHHOST
HTTP::uri $UPDATEDPATH
virtual "/path/virtual_server_name"
}
}For different route domain
when HTTP_REQUEST {
log local0. "Incoming request: [HTTP::host]:[HTTP::uri]"
if { [set match [class match -value -- "[HTTP::host]:[HTTP::uri]" starts_with datagroup_name]] ne "" } {
log local0. "Datagroup match: $match"
## Get first URI path in client request
set FIRSTPATH [getfield [HTTP::path] "/" 2]
## Split match into host and path
set matchlist [split $match ":"]
set MATCHHOST [lindex $matchlist 0]
set MATCHPATH [lindex $matchlist 1]
## Replace FIRSTPATH with MATCHPATH (from full HTTP::uri)
set UPDATEDPATH [string map [list "/$FIRSTPATH" "$MATCHPATH"] [HTTP::uri]]
log local0. "Updated host: $MATCHHOST"
log local0. "Updated path: $UPDATEDPATH"
HTTP::host $MATCHHOST
HTTP::uri $UPDATEDPATH
pool pool_name
}
}
In my opinion, with such a large amount of items you should use an iRule to perform this task, as it will be more beneficial for scalability and easier to manage.
How much will the URI paths change? Make sure to use [HTTP::uri] , [HTTP::path], [HTTP::query] parameters properly in order to isolate the parts of your old URL that you want to change/keep. For example you could save the full querystring in a variable so that you can add it back to the rewritten url.
If you have a large list of paths that all need to be rewritten on a single new path, you can also use data groups for even better scalability and maintenance.
This might give you a couple ideas
when HTTP_REQUEST {
set uri [HTTP::uri]; set path [HTTP::path]; set query [HTTP::query]
HTTP::header replace Host "pqr.com"
if { $path starts_with "/xyz" } {
set newpath [string map -nocase {"/xyz" "/mnp"} $path]
HTTP::uri "$newpath$query"
}
}
Hi CA_Valli,
How to incoroprate the different paths with the use of datagroup in the iRule provided above. Also when the response would come back doesn't it need to be changed to original URL+URI/path as well?
Thanks,
Prasenjit
- CA_ValliSep 22, 2022MVP
I've tried to modify my syntax, haven't had the chance to test it in a lab so please be careful with this and don't run it in prod without testing.
Code below is supposed to replace anything that matches /aaa/ /bbb/ or /ccc/ at depth1 in your path (this is driven by "starts_with" condition) with static /mnp/
so /aaa/path/to/index.jsp will change into /mnp/path/to/index.jsp/
and i believe /bbb/bbb/file.txt should change to /mnp/bbb/file.txt
Please also integrate knowledge shared by Kevin_Stewart in his comments which is very detailed and much more reliable than my attempt 🙂
Lastly, I don't think you will need to change anything in HTTP response.
when HTTP_REQUEST { set uri [HTTP::uri]; set path [HTTP::path]; set query [HTTP::query] HTTP::header replace Host "pqr.com" if {[class match $path starts_with datagroup_rewriteURL]} { set dgValue [class match -value $path eq datagroup_rewriteURL] ; #i believe this should return /xyz/ if you've set as a string entry in the data group log local0. "replacing $dgValue with /mnp/" set newpath [string map -nocase { $dgValue "/mnp/"} $path] HTTP::uri "$newpath$query" } }
ltm object will be something like
ltm data-group internal datagroup_rewriteURL { records { /aaa/ {} /bbb/ {} /ccc/ {} } type string }
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