Forum Discussion
Bibits_102724
Nimbostratus
Sep 09, 2010Need help with a redirect iRule
Hello,
I am new to iRules, and having problems getting it to work the way I hoped it would. What I want to solve is to redirect URLs according to the three examples below.
example 1:
http://my.website.no/database1/openurl.ashx?aulast=ludlum ==>
http://my.website.no/test/web/openurl.ashx?db=database1&unit=6465&aulast=ludlum
example 2:
http://my.website.no/database1 ==>
http://my.website.no/test/web/default.aspx?db=database1&unit=6465
example 3:
http://my.website.no/test/web/default.aspx?db=database1&unit=6465 ==>
http://my.website.no/test/web/default.aspx?db=database1&unit=6465
I also have a redirect file I figured would be on the format:
"/database1 db=database1&unit=6465",
Most requests will be on the format of example 3, where the request should pass untouched.
I was picturing an iRule structured somehing like the one below. But I can't even get a value into $left, so I must be doing something wrong. I am pretty sure that the 'split' and 'set left' commands worked yesterday, but when I try them now it doesn't work at all. I was also wondering if the reason for my problem is because split gives me a list, but I believe that when I fetch one value with "set left [lindex $params 0]" it should give me a string.
The way I think of doing this is to try to split an URI into two parts, the left ($left) and right ($right) side of "openurl.ashx?". I want to do this because if there is no "openurl.ashx" in the URI then I figure everything will end upp in $left
If there is no value in $right then I know that the URI is either on the format of example 2 or example 3. And if there is no value in $location I know that the URI is on the format of of example 3.
I am hoping that I can use the findclass method the way I am trying, but it depends of wether or not $left is really a string. I am also wondering if this is a reasonable way of structuring the iRule (if it ends up working at all), or if there is a more effective way,
Best regards,
Morten
----------------------------
Here is the draft for the iRule I am picturing:
when HTTP_REQUEST {
set params [split [HTTP::uri] "/openurl.ashx?"]
left holds the value for testing the file
set left [lindex $params 0]
right holds the appended query (if it exists)
set right [lindex $params 1]
find part of redirect location from file based on $left
set location [findclass $left $::redirect_file " "]
check if we have a match in the file
if { $location ne "" }{
check if we have an appended query
if { $right ne "" }{
we have a match in the file, and a query to append
HTTP::redirect "http://my.website.no/test/web/openurl.ashx?$location$right"
return
}
we only have a basic redirect and no query to append
HTTP::redirect "http://my.website.no/test/web/default.aspx?$location"
}
If no match so we do nothing
}
- The_Bhattman
Nimbostratus
Hi Morten,when HTTP_REQUEST { switch -glob [URI::path [HTTP::uri] 1 ] { Match anything that starts with /database1 "/database1/*" { set location [findclass [URI::path [HTTP::uri] 1 1] $::redirect_file " "] HTTP::redirection "http://[HTTP::host]/test/web/[URI::basename]?$location[URI::query]" } Exact match "/database1" { set location [findclass [URI::path [HTTP::uri] 1 1] $::redirect_file " "] HTTP::redirection "http://[HTTP::host]/test/web/default.aspx?$location" } If not match then do nothing } }
- Bibits_102724
Nimbostratus
Hello Bhattman,
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects