Nick_125548
Sep 11, 2013Nimbostratus
rewrite uri with datagroup
Hi
I'm new to irules and have got where I am but looking at other irules we have, but am still struggling.
I have a request from marketing to host a number (40) of small websites. Rather than setting up a new vip/pool/node/website for each one I would like to inspect the hostheader, forward it to a pool, rewrite the uri and be invisible to the user. This way I can simply copy the content to a single website. e.g.
nick.domain.co.uk/* -> forward to pool POC_Boxes -> uri rewritten to /nick/*
alan.domain.co.uk/* -> forward to pool POC_Boxes -> uri rewritten to /alan/*
lara.domain.co.uk/* -> forward to pool POC_Boxes -> uri rewritten to /lara/*
I have been able to get this working using a switch irule but would prefer a datagroup as it is easier to maintain going forward. However, I am having trouble reading data from the datagroup
here is my switch irule
when HTTP_REQUEST {
set marketingURI "[HTTP::uri]"
switch -glob -- [string tolower [URI::decode [HTTP::host]]] \
"nick.domain.co.uk" {
HTTP::uri "/nick$marketingURI"
pool POC_boxes
}
switch -glob -- [string tolower [URI::decode [HTTP::host]]] \
"lara.domain.co.uk" {
HTTP::uri "/lara$marketingURI"
pool POC_boxes
}
switch -glob -- [string tolower [URI::decode [HTTP::host]]] \
"alan.domain.co.uk" {
HTTP::uri "/alan$marketingURI"
pool POC_boxes
}
else {
HTTP::redirect "http://www.domain.com"
}
}
Here is my datagroup irule
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::host]] starts_with POC_DGL_Marketing_trades] } {
set url_URI [class match -value [string tolower [HTTP::host]] starts_with POC_DGL_Marketing_trades]
set marketingURI "$url_uri[HTTP::uri]"
HTTP::uri "$marketingURI"
pool POC_boxes
} else {
HTTP::redirect "http://www.domain.com"
}
log local0. "Marketing Trades [HTTP::host]"
}
Here is my datagroup
Name Value
nick.domain.co.uk /nick
alan.domain.co.uk /alan
lara.domain.co.uk /lara
Thanks
Nick