cancel
Showing results for 
Search instead for 
Did you mean: 

Irule or policy to URL rewrite

ckteur
Altostratus
Altostratus

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:

 

0691T00000CoWj1QAF.jpg 

 

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.

12 REPLIES 12

ckteur
Altostratus
Altostratus

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
Altostratus
Altostratus

Hi,

 

Nobody have an idea ?

Thanks.

 

Regards

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
Altostratus
Altostratus

SanjayP
MVP
MVP

Can you check again? I think you meant translation should be https://other.u.test.com/up/test1/test2

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
MVP
MVP

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
Altostratus
Altostratus

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

 

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 } } }

 

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
Altostratus
Altostratus

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/*

 

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?