Forum Discussion
Stripping part of URI and integrating with iRule
http://www.oursite.org/directory1/directory2/somepage.aspx needs to rewrite to http://oursite.org/somepage.aspx - essentially just stripping out directory1 and directory2.
I also need to be able to strip the www as well.
I've tried the following iRule that I found as hoolio's example, however it seems to end up getting stuck in a redirect loop.
I also do not want to string map, I need to actually rewrite the URI.
Can anyone tell me what I might be doing wrong? The bigip log shows:
Original URI: /directory1/directory2/somepage.aspx
Current URI: /somepage.aspx
Which seems to be correct, however redirect loop still occurs.
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: Original URI: [HTTP::uri]"
switch -glob [HTTP::path] {
"/directory1/directory2*" {
HTTP::uri [string map {"/directory1/directory2/" "/"} [HTTP::uri]]
HTTP::redirect "http://oursite.org[HTTP::uri]"
}
default {
HTTP::redirect "http://oursite.org"
}
}
}
when HTTP_REQUEST priority 501 {
log local0. "[IP::client_addr]:[TCP::client_port]: Current URI: [HTTP::uri]"
}
I then need to integrate this functionality into the bottom of this iRule, I've stripped most of it as it is very long. The following is at the very end of a large switch statement, and needs to be preserved
default {
if {[HTTP::uri] starts_with "/admin" } {
HTTP::redirect "http://legacy.oursite.org[HTTP::uri]"
} elseif {[string tolower [HTTP::host]] eq "www.oursite.org"}{
HTTP::redirect "http://oursite.org[HTTP::uri]"
}
}
Much thanks for any help!
- Joe_PipitoneNimbostratusYou da man! Works great man.
Thank you once again
- Chris_MillerAltostratusPosted By Joe Pipitone on 01/26/2011 01:18 PM
Thank you once again
For future reference, the wiki here is amazing.
http://devcentral.f5.com/wiki/defau...s.HomePage
Here's the list of iRules commands too, most of which have great examples.
https://devcentral.f5.com/wiki/defa...s.Commands
- Chris_MillerAltostratusOh, and before I forget. You should use "string tolower" to convert your URI to lower case before checking it. Otherwise, someone accidentally capitalizing any characters in their request will keep the rule from executing properly.
when HTTP_REQUEST { if { [string tolower[HTTP::uri]] starts_with "/directory1/directory2" } { HTTP::redirect "http://oursite.org/[string range [HTTP::uri] 11 end ]" log local0. "/directory1/directory2 found, redirected" } }
- Colin_Walker_12Historic F5 AccountNow that's some prompt help. Thanks Chris for all your help around here.
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