21-May-2021 06:51
Hello,
I need to rewrite URL with policy but doesn't work; maye will be usefull with an irule but I don't know how mahe it ...
My policy:
What I want with policy or Irule:
original URL: https://client.u.test.com/up
Rewrite URL: https://other.u.test.com/up (all ressources can be call after up like https://other.u.test.com/up/.*)
Forwarding : to pool xxxxx
Thanks for help.
Regards.
21-May-2021 07:44
I try this but doesn't still work:
if {[string tolower [HTTP::host]] starts_with "client.u.test.com" && [HTTP::uri] starts_with "/up" }
{ HTTP::header replace host "other.u.test.com"
HTTP::uri "/up/.*"
pool Pool_other.u.test.com_1443
}
25-May-2021 00:37
Can you give more details on url rewrite/translation. e.g. if incoming url is https://client.u.test.com/up/test1/test2, what should be the rewrite url?
25-May-2021 06:41
if incoming URL is https://client.u.test.com/up/test1 the rewrite will be https://other.u.test.com/up/test2
25-May-2021 06:50
Can you check again? I think you meant translation should be https://other.u.test.com/up/test1/test2
25-May-2021
06:58
- last edited on
04-Jun-2023
20:53
by
JimmyPackets
There is still confusion around, how uri after /up should be translated. If you can provide more details on it then it would be clear. But I'm assuming those shouldn't be changed. Considering it won't change, you can use below iRule
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
switch -glob [string tolower [HTTP::host]] {
"client.u.test.com" {
if {$uri starts_with "/up" } {
HTTP::header replace "Host" "other.u.test.com"
pool Pool_other.u.test.com_1443
return
}
}
default {
return
}
}
}
If you need any other rewrite rule with uri after /up let me know and we can modify the iRule above
25-May-2021 07:08
Try this
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] contains "client.u.test.com") and [HTTP::uri] starts_with "/up" } {
HTTP::header replace Host "other.u.test.com"
pool Pool_other.u.test.com_1443
}
}
25-May-2021 07:09
Thanks Sanjay.
Actually I need to modify the host (it's ok in your iRule: client.u.test.com
--> other.u.test.com) but also the path after the first "/" --> client.u.test.com/up is rewrited other.u.test.com/down
25-May-2021
07:21
- last edited on
04-Jun-2023
20:53
by
JimmyPackets
okay. You can use below
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
switch -glob [string tolower [HTTP::host]] {
"client.u.test.com" {
if {$uri starts_with "/up" } {
HTTP::header replace "Host" "other.u.test.com"
HTTP::uri /[join [lreplace [split [string trimleft [HTTP::uri] /] /] 0 0 "down"] /]
pool Pool_other.u.test.com_1443
return
}
}
default {
return
}
}
}
25-May-2021 10:54
I haven't been able to test yet, I will do it tomorrow...
I forgot to say that the rewrite must allow all the possibilities behind "/down"
like "other.u.test.com/down/*"
Thanks for help
26-May-2021 04:28
Hi,
It doesn't work ....
Actually I just need to rewrite client.u.test.com/up -> other.u.test.com/down but with possibilities to add any sting after /down like other.u.test.com/down/*
27-May-2021 02:21
what error do you receive? Above iRule does the same where it will rewrite the HOST header and rewrite the url by replacing /up by /down and add all other uri after /down
Please enable logging in iRule to see what's happening?