Forum Discussion
Irule Datagroup redirect
I have following URLs that need to be redirected using Datagroup and irule but i can't figure out the irule or data set
https://www.abc.ca/marrow/Overview > https://test.abc.ca/stashtest
https://www.abc.ca/marrow/Sponsors > https://xyz.ca.ca/stashbwards/list
https://www.abc.ca/marrow/Sponsors?N=105098 > https://xyz.ca.ca/stashbwards/list?stash_bward_filter=boucher
https://www.abc.ca/marrow/Sponsors?N=105099 > https://xyz.ca.ca/stashrewards/list?stash_bward_filter=in-store
https://www.abc.ca/marrow/SponsorsDetails?Nr=vendor.id:100218 > https://xyz.ca.ca/stashrbwards/touterer/88991
https://www.abc.ca/marrow/SponsorsDetails?Nr=vendor.id:100245 > https://xyz.ca.ca/stashrbwards/boucher/89021
https://www.abc.ca/marrow/BewardsProductList?a=true&selectedCategoryId=cat70001 > https://xyz.ca/merks
I have tried something like
datagroup name= test1
key= /marrow/Overview value=test.abc.ca/stashtest
or
key=www.abc.ca/marrow/Overview and value=test.abc.ca/stashtest
with following irule
when HTTP_REQUEST {
if { [class match [HTTP::host][HTTP::uri] equals test1] }
{set redirect_value [class match -value [HTTP::host][HTTP::uri] eq test1]
HTTP::respond 301 Location
HTTP::redirect "http://$redirect_value"
}
}
But it does not seem to work. I am using Big-IP 11.6
Hi Jawed,
Data-group:
ltm data-group internal test { records { www.abc.ca/marrow/BewardsProductList\?a=true&selectedCategoryId=cat70001 { data xyz.ca/merks } www.abc.ca/marrow/Overview { data test.abc.ca/stashtest } www.abc.ca/marrow/Sponsors { data xyz.ca.ca/stashbwards/list } www.abc.ca/marrow/SponsorsDetails\?Nr=vendor.id:100218 { data xyz.ca.ca/stashrbwards/touterer/88991 } www.abc.ca/marrow/SponsorsDetails\?Nr=vendor.id:100245 { data xyz.ca.ca/stashrbwards/boucher/89021 } www.abc.ca/marrow/Sponsors\?N=105098 { data xyz.ca.ca/stashbwards/list\?stash_bward_filter=boucherstore } www.abc.ca/marrow/Sponsors\?N=105099 { data xyz.ca.ca/stashrewards/list\?stash_bward_filter=in-store } abc.ca/marrow/BewardsProductList\?a=true&selectedCategoryId=cat70001 { data xyz.ca/merks } abc.ca/marrow/Overview { data test.abc.ca/stashtest } abc.ca/marrow/Sponsors { data xyz.ca.ca/stashbwards/list } abc.ca/marrow/SponsorsDetails\?Nr=vendor.id:100218 { data xyz.ca.ca/stashrbwards/touterer/88991 } abc.ca/marrow/SponsorsDetails\?Nr=vendor.id:100245 { data xyz.ca.ca/stashrbwards/boucher/89021 } abc.ca/marrow/Sponsors\?N=105098 { data xyz.ca.ca/stashbwards/list\?stash_bward_filter=boucherstore } abc.ca/marrow/Sponsors\?N=105099 { data xyz.ca.ca/stashrewards/list\?stash_bward_filter=in-store } } type string }
iRule:
when HTTP_REQUEST { if { [class match [HTTP::host][HTTP::uri] equals test1] } { set redirect_value [class match -value [HTTP::host][HTTP::uri] equals test1] HTTP::respond 301 Location "https://$redirect_value" } }
If you want to use without datagroup:
when HTTP_REQUEST { if { [HTTP::host] equals "www.abc.ca" || [HTTP::host] equals "abc.ca" } { switch -glob [string tolower [HTTP::uri]] { "/marrow/overview/" { HTTP::respond 301 Location "https://test.abc.ca/stashtest" } "/marrow/sponsors" { HTTP::respond 301 Location "https://xyz.ca.ca/stashbwards/list" } "/marrow/sponsors?n=105098" { HTTP::respond 301 Location "https://xyz.ca.ca/stashbwards/list?stash_bward_filter=boucher" } "/marrow/sponsors?n=105099" { HTTP::respond 301 Location "https://xyz.ca.ca/stashrewards/list?stash_bward_filter=in-store" } "/marrow/sponsorsdetails?nr=vendor.id:100218" { HTTP::respond 301 Location "https://xyz.ca.ca/stashrbwards/touterer/88991" } "/marrow/sponsorsdetails?nr=vendor.id:100245" { HTTP::respond 301 Location "https://xyz.ca.ca/stashrbwards/touterer/89021" } "/bewardsproductlist?a=true&selectedcategoryid=cat70001" { HTTP::respond 301 Location "https://xyz.ca/merks" } } } }
- whootang
Nimbostratus
I did something similar
I run a redirect service on one vip with the following irule
when HTTP_REQUEST { if {[set redir_host [class match -value -- [string tolower [HTTP::host]] equals bulk-redirect]] ne "" }{ HTTP::redirect $redir_host } }
then in the data group list i have the ursl i want added
String set to : url you want redirected
Value: new url
- baboo1970
Altostratus
thanks eaa and whootang. I tried one rule as example it worked. So i can't thank you enough; really appreciate prompt response and the right one that corked too.
- baboo1970
Altostratus
if i want to incorporate case insensitivity into this; will i need to tweak the irule or Datagroup?
what that tweak will be? This is the iRule i am using currently
- when HTTP_REQUEST {
- if { [class match [HTTP::host][HTTP::uri] equals test1] } {
- set redirect_value [class match -value [HTTP::host][HTTP::uri] equals test1]
- HTTP::respond 301 Location "https://$redirect_value"
- }
- }
If you want case sensitivity, datagroup strings sholud be lower case. And you can use this iRule.
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host][HTTP::uri]] equals test1] } { set redirect_value [class match -value [string tolower [HTTP::host][HTTP::uri]] equals test1] HTTP::respond 301 Location "https://$redirect_value" } }
You don't need to change datagroup values(redirect_value). They can be contains upper case.
- baboo1970
Altostratus
Thanks very much. this worked and now moving onto next challenge as current one is doing exact match in DataGroup but what if requested URL or Destination is not exact match but something starts_with or contains etc... Don't even know where to start with this as i don't know what is actual structure of the HTTP request.
- baboo1970
Altostratus
I am using this iRule
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::host][HTTP::uri]] starts_with test] } {
set redirect_value [class match -value [string tolower [HTTP::host][HTTP::uri]] equals test]
HTTP::respond 301 Location "https://$redirect_value"
}
}
while my datagroup looks like
https://www.abc.ca/marrow/Overview > https://test.abc.ca/stashtest
https://www.abc.ca/marrow/Sponsors > https://xyz.ca.ca/stashbwards/list
I am expecting that when someone hist the VIP with https://abc.ca/marrow/Overview?changeLocale=en_CA VS https://www.abc.ca/marrow/Overview then it will still redirected to https://test.abc.ca/stashtest
but that does not seem to work.
I am not sure what to change to make it work. Any help will be much appreciated.
- gersbah
Cirrostratus
If you want to match regardless of the query string, use [HTTP::path] instead of [HTTP::uri]
And if you have different cases of what is to be matched, split them up by type, e.g. one datagroup and if/elseif condition for starts_with, one for exact match, one including query string, etc.
Or use the datagroup for your "default" case and hardcode the exceptions in your iRule if it's just a handful.
Depends on your preference, how many redirects there are and how often you expect them to change.
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