Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

replace part of URI for specific URL and pass remaining

iRule
Cirrus
Cirrus

Dear Community,

I need to replace only specific part of  URI i.e "/abc/defg/" with "/uvw/xyz/"  in a URL. All other URLs should not be altered.

"/abc/defg/" will appear in the begning of URI

For example:

From: https://bbcc.com/abc/defg/v1/derh/user-cases/ profile/morning

To:      https://bbcc.com/uvw/xyz/v1/derh/user-cases/ profile/morning

All Other URLs should not be alerted and sent to pool without modification in URI.

Regards

1 ACCEPTED SOLUTION

@iRule It should be the following and any other additions can be added in a similar manner. You might consider speaking with the application team and have them perform the corrections on the server as this should only be done as a last resort in an iRule.

when CLIENT_ACCEPTED priority 500 {

    set DEFAULT_POOL [LB::server pool]

}

when HTTP_REQUEST priority 500 {

    if {[string tolower [HTTP::uri]] starts_with "/abc/defg/"} {
        HTTP::uri [string map {"/abc/defg/" "/uvw/xyz/"}[HTTP::uri]]
        pool pool_web
    } elseif {[string tolower [HTTP::uri]] starts_with "/123/456/"} {
        HTTP::uri [string map {"/123/456/" "/78/910/"}[HTTP::uri]]
        pool pool_web
    } elseif{[string tolower [HTTP::uri]] starts_with "/asdf-asdf/"} {
        HTTP::uri [string map {"/asdf-asdf/" "/lkjh-lkjh/"}[HTTP::uri]]
        pool pool_web
    } else {
        pool ${DEFAULT_POOL}
    }

}

View solution in original post

10 REPLIES 10

iRule
Cirrus
Cirrus

I tried following iRule but it results in URIs starting with "/abc/defg/working fine and all other URLs stopped working which are not starting with "/abc/defg/".

 

when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/abc/defg/"} {
HTTP::uri [string map {"/abc/defg/" "/uvw/xyz/"}[HTTP::uri]]
pool pool_web
}
}

 

@iRule I have made some slight modifications to the iRule but I don't think it will resolve your issue but are best practices.

when HTTP_REQUEST priority 500 {

    if {[string tolower [HTTP::uri]] starts_with "/abc/defg/"} {
        HTTP::uri [string map {"/abc/defg/" "/uvw/xyz/"}[HTTP::uri]]
        pool pool_web
    }

}

If you can provide additional detail as to what exactly isn't working for the additional URLs we might be able to assist further.

@Paulius All other URLs that are not starting with "/abc/defg/" are stopped and I am getting connection reset error. Kindly provide an updated iRule.

@iRule Do you have pool configured for the VS that your iRule is configured under? It would be helpful to see the configuration of your VS in order to properly configure an iRule to perform the task that you are expecting.

@Paulius yes pool is configured under virtual server

@iRule The irule above should work but the following can be used to see if that fixes your issue in conjunction with a /32 OneConnect profile associated to the VS.

when CLIENT_ACCEPTED priority 500 {

    set DEFAULT_POOL [LB::server pool]

}

when HTTP_REQUEST priority 500 {

    if {[string tolower [HTTP::uri]] starts_with "/abc/defg/"} {
        HTTP::uri [string map {"/abc/defg/" "/uvw/xyz/"}[HTTP::uri]]
        pool pool_web
    } else {
        pool ${DEFAULT_POOL}
    }

}

This iRule is under testing and I shall keep you posted on results, Thank you

@Paulius The iRule provided by you worked fine with Thanks but application team has now enhanced the requirment for us to it achieve from f5 iRule.

Enhanced requirement is as following

Replace URI keywords

FROM: https://bbcc.com/abc/defg/v1/derh/user-cases/profile/morning TO: https://bbcc.com/uvw/xyz/v1/derh/user-cases/profile/morning

OR

FROM: https://bbcc.com/123/456/v1/derh/morning/evening/night TO: https://bbcc.com/78/910/v1/derh/morning/evening/night

OR

FROM: https://bbcc.com/asdf-asdf/school/college/university TO: https://bbcc.com/lkjh-lkjh/school/college/university

All Other URLs should not be alerted and sent to pool without modification in URI.

Please help in achiveing this.

Regards

 

 

@iRule It should be the following and any other additions can be added in a similar manner. You might consider speaking with the application team and have them perform the corrections on the server as this should only be done as a last resort in an iRule.

when CLIENT_ACCEPTED priority 500 {

    set DEFAULT_POOL [LB::server pool]

}

when HTTP_REQUEST priority 500 {

    if {[string tolower [HTTP::uri]] starts_with "/abc/defg/"} {
        HTTP::uri [string map {"/abc/defg/" "/uvw/xyz/"}[HTTP::uri]]
        pool pool_web
    } elseif {[string tolower [HTTP::uri]] starts_with "/123/456/"} {
        HTTP::uri [string map {"/123/456/" "/78/910/"}[HTTP::uri]]
        pool pool_web
    } elseif{[string tolower [HTTP::uri]] starts_with "/asdf-asdf/"} {
        HTTP::uri [string map {"/asdf-asdf/" "/lkjh-lkjh/"}[HTTP::uri]]
        pool pool_web
    } else {
        pool ${DEFAULT_POOL}
    }

}

The above iRule logic worked

Thank you