Forum Discussion
Irule or policy to URL rewrite
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.
- ckteur
Cirrus
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
}
- ckteur
Cirrus
Hi,
Nobody have an idea ?
Thanks.
Regards
- spalande
Nacreous
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?
- ckteur
Cirrus
if incoming URL is https://client.u.test.com/up/test1 the rewrite will be https://other.u.test.com/up/test2
- spalande
Nacreous
Can you check again? I think you meant translation should be https://other.u.test.com/up/test1/test2
- spalande
Nacreous
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
- P_K
Altostratus
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
}
}
- ckteur
Cirrus
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
- spalande
Nacreous
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 } } }
- ckteur
Cirrus
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
- ckteur
Cirrus
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/*
- spalande
Nacreous
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?
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