We are working on a Web site refresh and have been asked to use BIG-IP to redirect over 1000 pages based on URI to a different URI on same page. We have different options to do this with I-rule but I have never did an I-rule with 1000 plus redirects. Is one of the options below better than the other when there is so many redirects?
when HTTP_REQUEST { if {[HTTP::path] eq " /aboutus/ContactUs/index.html"}{ HTTP::redirect “http://[HTTP::host]/en/about/contact” } Repeat IF for every URI redirect }
OR Option 2
when HTTP_REQUEST {
if { [HTTP::uri] starts_with “/aboutus/ContactUs/index.html”}{
Also notice that the left side is all lowercase, because you’re evaluating a [string tolower ] match in the iRule. In this way you can manage a 1000 line data group list instead of a much larger and much more complicated iRule.
iControl is another option to build data groups. I’ve used this extensively for adding records into data groups by iterating through a CSV file containing /olduri/ and /new/uri key/value pairs…
function Add-DataGroupValues()
{
param([string]$dataGroupName,[string[]]$dataGroupMember,[string]$dataGroupValue)
$stringClass = New-Object -TypeName iControl.LocalLBClassStringClass
$stringClass.name = $dataGroupName
$stringClass.members = ((,$dataGroupMember))
(Get-F5.iControl).LocalLBClass.add_string_class_member((,$stringClass))
$stringValueClass = New-Object -TypeName iControl.LocalLBClassStringClass
$stringValueClass.name = $dataGroupName
$stringValueClass.members = ((,$dataGroupMember))
$values = (Get-F5.iControl).LocalLBClass.set_string_class_member_data_value($stringValueClass,$dataGroupValue)
}
Get the CSV info
$records = Get-CSVInfo
Add to data group
foreach($record in $records)
{
$dataGroupMember = $record.Name
$dataGroupValue = $record.Value
Add-DataGroupValues $dataGroupName $dataGroupMember $dataGroupValue
}
(Get-F5.iControl).SystemConfigSync.save_configuration("bigip.conf","SAVE_FULL")
We implemented and it doesn’t redirect correctly. Below is I-rule and a sample of Data Group. Would this type of redirect have issue on 10.2.4 Build 655.0 Hotfix HF4? I see I-rule being executed on statistices. Is there any other ways to troubleshoot this?
I-rule
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::uri]] starts_with redir_dg] } {
HTTP::redirect http://[HTTP::host][class match -value [string tolower [HTTP::uri]]
starts_with redir_dg]
When you say “it doesn’t redirect correctly”, what do you mean exactly? Does it not redirect at all, or are there unintended actions taken? Any errors in the logs?
Observations: 1. “/index.html” = “/”, so you’ll want to add both to the data group. 2. Using [HTTP::path] is a bit leaner than using [HTTP::uri]. 3. HTTP::redirect generates a 302, which is not cached. It would be better to use HTTP::respond 301 Location http://[HTTP::host][class match -value [string tolower [HTTP::uri]] starts_with redir_dg] 4. Consider using quotation marks around the Location, just in case someone uses spaces or other troublesome characters in the Location. 5. One of the problems with Data Groups is that (depending on how they’re updated), updating the DG temporarily makes it unavailable and/or will contain no data or merely a subset of the data. Although the duration of this error condition is brief, it can be problematic. 6. If any other redirects or responses are generated on the connection you’ll get an error (“multiple responses”). Code accordingly.
I found my issue. Some worked and others did not. The ones that didn’t work I had uppercase letters in my Data Group. I tried to copy and past a list i recieved from the web team to save time but it ended up bitting me. Thank you for the quick repsonce! it ended up being a case of upper case Datagroup when I-rule specifically changes to lower case!