Forum Discussion
Best way to redirect multiple URI's to a full URL
Hi, have multiple URI's that need to be redirected to the full URL, for example
/dev/v1/fedEx/fedexlabel-shipment REDIRECT TO: https://dev-warehouse-papi-dev.cloudhub.io/rest/v1/warehouse/fedExShipment
What is the best way to do this? Should I use an irule with a Data Group List? What would the irule and data group list look like?
- AMiles_377865
Cirrocumulus
Hello John,
An iRule and data group would probably be easiest, yes. Make a string data group with the uri's that need to be redirected, and use that to decide the redirect. Here's a pretty good video on data groups if you need a refresher, and this post covers the basic steps on making an external group if your list of uris is big.
Here's some pseudo-code to get you on the right track for the iRule.
when HTTP_REQUEST { if { [class match [HTTP::uri] equals uriGroup] } { HTTP::redirect https://dev-warehouse-papi.dev.cloudhub.io/rest/v1/warehouse/fedExShipment } }
That should work for v. 10 and above. I think older versions use matchclass instead of class, which would look like
if { [matchclass[HTTP::uri] equals uriGroup] } {
Best of luck,
Austin
- jmolchin_47123
Nimbostratus
Would this hold true even though the redirect is different for each URI
/dev/v1/fedEx/fedexlabel-shipment https://dev-warehouse-papi-dev.cloudhub.io/rest/v1/warehouse/fedExShipment
/test/v1/fedEx/fedexlabel-shipment https://dev-warehouse-papi-test.cloudhub.io/rest/v1/warehouse/fedExShipment
/dev/WshSendTxnToOtmService/WshSendTxnToOtmService https://dev-otm-papi-dev.cloudhub.io/WshSendTxnToOtmService/WshSendTxnToOtmService
/test/WshSendTxnToOtmService/WshSendTxnToOtmService https://dev-otm-papi-test.cloudhub.io/WshSendTxnToOtmService/WshSendTxnToOtmService
- AMiles_377865
Cirrocumulus
Okay yeah, there's a couple options you could try. My first thought is that each entry in the database could have a specific value that you use to differentiate between your redirects.
database: uriGroup string1: /example value1: https://dev-warehouse-papi-dev.cloudhub.io/rest/v1/warehouse/fedExShipment string2: /test value2: https://dev-otm-papi-test.cloudhub.io/WshSendTxnToOtmService/WshSendTxnToOtmService
Rinse and repeat.
HTTP::redirect https:// [class match -value [HTTP:uri] equals uriGroup ]
and then something like that for the code, which should redirect you based on the value you entered for that uri entry
- jmolchin_47123
Nimbostratus
my iRule is
when HTTP_REQUEST { if { [class match [HTTP::uri] equals DGL1] } { HTTP::redirect https:// [class match -value [HTTP:uri] equals DGL1 ]
}
}
Will be testing tomorrow. Thanks for your help
- jmolchin_47123
Nimbostratus
This is the iRule that calls to the data group list that contains the URI's and the redirected URL's works fine.
Does anyone know if you can use the F5 as a reverse proxy when using a data group list that redirects the client? The only resource applied to the virtual server is the iRule. I'd like the clients request to get redirected and proxied by the F5.
when HTTP_REQUEST { log local0. "URI equals [HTTP::uri]" if { [class match [HTTP::path] equals DGL1] } { set key [class match -name [HTTP::path] contains DGL1] set value [class match -value $key contains DGL1] HTTP::respond 302 Location "$value" } }
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