Forum Discussion
pedinopa_170325
Nimbostratus
Oct 03, 2016irule to edit a URI
I have been working on an irule that will edit a URI string. What I need it to do is simply add a .domain.com after the first directory of the uri path and redirect to the new URI. I have it kind o...
Oct 03, 2016
Hi!
You might want to try the syntax highlighting function. Otherwise your irules will be hard to interpret.
One thing that could be the issue with your original irule was that you set the case to lower and then match against capital letters (not sure if this was just an example gone bad though).
I might have tried to parse the directory instead of doing switch glob. Try this one?
when HTTP_REQUEST {
HSL::send $hsl "This is the HTTP URI [HTTP::uri]"
HSL::send $hsl "This is the HTTP Path [HTTP::path]"
set directory [lindex [split [string tolower [HTTP::uri]] "/"] 1]
switch $directory {
"dir1" {
set switches [string map {"/$directory/" "/"} [string tolower [HTTP::uri]]]
HTTP::redirect "http://dir1.domain.com/$switches"
}
"dir2" {
set switches [string map {"/$directory/" "/"} [string tolower [HTTP::uri]]]
HTTP::redirect "http://dir2.domain.com/$switches"
}
"dir3" {
set switches [string map {"/$directory/" "/"} [string tolower [HTTP::uri]]]
the switches will be everythi from the origional URI after the first directory
HTTP::redirect "http://dir3.domain.com/$switches"
}
"dir4" {
HTTP::redirect "http://dir4.domain.com/"
}
"dir5" {
HTTP::redirect "http://dir5.domain.com"
}
"dir6" {
HTTP::redirect "http://dir6.domain.com"
}
}
}
/Patrik
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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