Forum Discussion
irule for URL remap
Hi All,
I have a situation where I need some help with an Irule , the scenario is when a client access a VIP with the URL " https:///XXXX/./" ,it needs to be remapped to "http://../XXXX/" when sending out to the backend server.
Note: ( YYYY,ZZZZ,dns_name components can dynamically change depending on the data resources that needs to be accessed on backend server )
- RF5_247672
Nimbostratus
This is the right format of the URL remap
Client -----> BIGIP --- *
BIGIP ----> Backend server --- *
- Kevin_Davies
Nacreous
Maps any of the following requests
https://my.server.com/everything?is=awesome https://MY.SERVER.COM/everything?is=awesome https://my.server.com:9000/everything?is=awesome
to backend request
/my.server.com/everything?is=awesome
iRule as follows
when HTTP_REQUEST { HTTP::uri "/[string tolower [getfield [HTTP::host] {:} 1]][HTTP::uri]" }
- nsandeep123_239
Nimbostratus
Below is the better explanation of the question
Hi All,
I have a situation where I need some help with an Irule , the scenario is when a client access a VIP with the URL " Client -----> BIGIP --- * , it needs to be remapped to
BIGIP ----> Backend server --- *
Note: ( name1,name2,name3 components can dynamically change depending on the data resources that needs to be accessed on backend server )
- Kevin_Davies
Nacreous
Your load balancing will select the pool member so is not used to select the actual server. We can change the URI and Host header on the way to the pool and thats it.
when HTTP_REQUEST { foreach {ignore name2 name34 rest} [split [HTTP::uri] {/}] break HTTP::host "$name34.[getfield [HTTP::host] {:} 1]" HTTP::uri "/$name2/$rest" }
- RF5_247672
Nimbostratus
Thank you kevin for the response, is the below irule will do the URI rewrite , if the browser/client hits the F5 vip with http://name.domain.com/abc/ten/spa and the backend server should receive with uri rewrite as http://spa.ten.name.domain.com/abc
On the LTM by doing a curl command it shows that uri rewrite happens , but when we checked HTTP_RESPONSE log and the backend server log, it receives the request as it is ( http://name.domain.com/abc/ten/spa )
did I miss something in the irule ? please advise
when HTTP_REQUEST {
set vip [IP::local_addr]:[TCP::local_port] set url [HTTP::header Host][HTTP::uri] set URI [string tolower [HTTP::uri]] if {[HTTP::uri] contains "/abc/"} { scan $URI {/%[^/]/%[^/]/%[^/]/} a b c log local0. $b log local0. $c **HTTP::uri "http://$c.$b.name.domain.com/abc/"** log local0. [HTTP::uri] } else{ scan $URI {/%[^/]/%[^/]/} a b log local0. $a log local0. $b HTTP::uri "http://$b.$a.name.domain.com/" log local0. [HTTP::uri] }
}
when HTTP_RESPONSE {
set client [IP::client_addr]:[TCP::client_port]
set node [IP::server_addr]:[TCP::server_port]
set nodeResp [HTTP::status]
log local0.info "Client: $client -> VIP:$vip$url -> Node: $node with response $nodeResp"
}
- Kevin_Davies
Nacreous
HTTP_RESPONSE deals with the information sent to you from the server. This has nothing to do with the iRule provided which deals entirely with traffic being passed to the server. The two are not the same. While one is caused by the other, traffic going to the server is generated by the client. Traffic coming from the server is generated by the server in response to the request from the client. Since this is not being modified you get it as is.
If this is not what you want the you need to modify the original iRule to modify the response from the server. Because this is now modifying content and no longer just a header this becomes more complicated. I think you should resubmit your original request with a lot more information. Then you are far more likely to get a response which gives you the desired outcome.
- RF5_247672
Nimbostratus
Kevin,
Ignore the HTTP Response part, I have just kept that for logging purpose. The original request was to rewrite the uri before sending it to the server
client ---- BIGIP : http://name.domain.com/abc/ten/spa/
BIGIP --- server : http://spa.ten.name.domain.com/abc/
The below irule will do the works as per the requirement?
IRULE:
when HTTP_REQUEST {
if {[HTTP::uri] contains "/abc/"} {
scan $URI {/%[^/]/%[^/]/%[^/]/} a b c
log local0. $b
log local0. $c
HTTP::uri "http://$c.$b.name.domain.com/abc/"
log local0. [HTTP::uri] }
else{
scan $URI {/%[^/]/%[^/]/} a b
log local0. $a
log local0. $b
HTTP::uri "http://$b.$a.name.domain.com/"
log local0. [HTTP::uri]
}
- Stanislas_Piro2
Cumulonimbus
Hi,
did you tried rewrite profile?
- rewrite mode : URI translation
-
rule 1 :
- direction : both
- client URI : http://name.domain.com/abc/ten/spa/
- server URI : http://spa.ten.name.domain.com/abc/
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