Forum Discussion
Data group "/" definition
Hi Experts,
Thanks in advance for your time and respond to this question.
I have request to redirect couple of URLs to specific site.
https://abc.com/ or https://abc.com/uri1 or https://abc.com/uri2 then redirect to https://def.com otherwise redirect to pool members
I decided to use data-group to list out all URLs in one data group and reference that data group in irule. one thing I am not sure about it how F5 would understand for https://abc.com/ in the list.
Does it take just as a host URL or host with any URIs? because client only want to redirect specified URIs to the def.com, everything else would be redirect to pool members?
Thanks
13 Replies
- Brad_Parker
Cirrus
With https://abc.com/, the [HTTP::uri] equals "/". With https://abc.com/uri2, the [HTTP::uri] equals "/uri2". I hope this can provide some clarity.
- Anush
Nimbostratus
Thanks for your reply. so if I have following list in data group / := /uri1 := /uri2 := Does the first line take as https://abc.com or https://abc.com includes any URI after that? Thanks
- Brad_Parker_139
Nacreous
With https://abc.com/, the [HTTP::uri] equals "/". With https://abc.com/uri2, the [HTTP::uri] equals "/uri2". I hope this can provide some clarity.
- Anush
Nimbostratus
Thanks for your reply. so if I have following list in data group / := /uri1 := /uri2 := Does the first line take as https://abc.com or https://abc.com includes any URI after that? Thanks
- Michael_Jenkins
Cirrostratus
I think you're best bet if you want to use a data group would be to put the source host and uri as the name and then the redirect host (& uri) as the value. Then, in your irule you would just use the class command to search the datagroup for the host and uri. Something like this might work. (Note: it will ignore your protocol, so you'd only be checking on
instead ofabc.com
. Need to be sure you enter the data group items in based on that.)http://abc.comwhen HTTP_REQUEST { set key [string tolower "[HTTP::host][HTTP::uri]"] if { [class match $key equals DATA_GROUP_NAME] } { HTTP::respond 302 [class match -value $key equals DATA_GROUP_NAME] return } } - Michael_Jenkins
Cirrostratus
The
command will only give the host name ("abc.com"). It won't give your the protocol. So you don't want to use that when you're comparing because it'll never be equal.HTTP::hostYour iRule's logic will work as long as you want any host that has one of the uris specified in the data group to be redirected to def.com. That means that
would go tohttps://abc.com/uri1
, as well ashttps://def.com
would be redirected as well.https://def.com/uri1Are you trying to redirect everything with a specific URI to def.com, or only certain hosts like abc.com?
- Brad_Parker
Cirrus
give this a try:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } { HTTP::redirect "https://def.com" } elseif { [class match [string tolower [HTTP::uri]] starts_with "/Common/URL_REDIRECT"] } { HTTP::redirect "https://def.com" } else { pool POOL_NAME } }- Anush
Nimbostratus
Thanks Brad. One last question. I am using GUI to add list of URIs in data group /uri1 := /uri2 := is this the correct syntax? Thanks - Brad_Parker
Cirrus
yep, that will work.
- Brad_Parker_139
Nacreous
give this a try:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } { HTTP::redirect "https://def.com" } elseif { [class match [string tolower [HTTP::uri]] starts_with "/Common/URL_REDIRECT"] } { HTTP::redirect "https://def.com" } else { pool POOL_NAME } }- Anush
Nimbostratus
Thanks Brad. One last question. I am using GUI to add list of URIs in data group /uri1 := /uri2 := is this the correct syntax? Thanks - Brad_Parker_139
Nacreous
yep, that will work.
- Anush
Nimbostratus
Hi Brad,
I made little modification in the script and works just fine..
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com" && [HTTP::uri] equals "/" } { HTTP::redirect "https://def.com" } elseif { [class search URL_REDIRECT starts_with [HTTP::uri]] } { HTTP::redirect "https://def.com" } else { pool POOL_NAME } }
Thanks
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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