Forum Discussion
Sean_O_Brien_65
Nimbostratus
Feb 23, 2011Looking for iRule to forward based on uri
I have an iRule here:
when HTTP_REQUEST {
if {[HTTP::uri] eq "/proposals/webpagenumber1*" } {
HTTP::redirect "http://domain2.com/Services_and_Products/sub1/sub2/Proposals/webpage1"
}
}
But this isn't working in testing... I have tried using wildcards as shown above and other combinations... but the original page is still being displayed.
I have 10 different uri (pages) from this domain1.com that needed to be redirected to different uri's on domain2.com.
Is there a simpler way to do this? using 'switch' command?
Basically, a bunch of these with different pages:
http://domain1.com/proposals/webpagenumber1.htm
to
http://domain2.com/Services_and_Products/sub1/sub2/Proposals/webpage1
Thanks!
3 Replies
- hoolio
Cirrostratus
Hi Sean,
If the comparisons are all the same (check if [HTTP::uri] starts with the list of URIs), you could put all of the URI patterns in a datagroup. You can then use finndclass (v9) or class search -value (v10) to look up the current URI against the datagroup.
http://devcentral.f5.com/wiki/default.aspx/iRules/findclass
http://devcentral.f5.com/wiki/default.aspx/iRules/class
Aaron - Sean_O_Brien_65
Nimbostratus
So after some more playing, I ended up with this, which works fine:
when HTTP_REQUEST {
if {[HTTP::uri] eq "/proposals/AccessControl.htm" } {
HTTP::redirect "http://domain2.com/sub1/Construction/Proposals/AccessControl"
}
if {[HTTP::uri] eq "/proposals/Davis.htm" } {
HTTP::redirect "http://domain2.com/sub1/Construction/Proposals/Maintenance"
}
if {[HTTP::uri] eq "/" } {
HTTP::redirect "http://domain2.com/sub1/Construction"
}
}
My only remaining question is: Can I use a better 'default' for that last line to go to the 'home' of the site than the "/". If people type in anything other than the domain name, or the "/" they will not get forwarded.
Thanks again for the help! - hoolio
Cirrostratus
You can use a switch statement for this as well. It's more efficient as you're not performing all three checks if a prior check was true.when HTTP_REQUEST { switch [HTTP::path] { "/proposals/AccessControl.htm" { HTTP::redirect "http://domain2.com/sub1/Construction/Proposals/AccessControl" } "/proposals/Davis.htm" { HTTP::redirect "http://domain2.com/sub1/Construction/Proposals/Maintenance" } default { HTTP::redirect "http://domain2.com/sub1/Construction" } } }
If you have a lot more URIs to check for and they're all exact matches, you could add all of them to a string datagroup with a 'string' of the URI and a value which is the redirect URL. You can check the class wiki page for examples:
http://devcentral.f5.com/wiki/default.aspx/iRules/class
Aaron
Aaron
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
