Forum Discussion
Bob_10976
Nimbostratus
Mar 25, 2010Rewrite rule not working, what am I missing?
I have this iRule that works fine, with the exception of the last entry, which I can't seem to get to take. This is assiged to our MOSS farm, so we have several web sites under one pool. I added the log entries to see if the rule was even being hit and i'm not seeing anything in the LTM's log files.
Any suggestions would be greatly appreciated.
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "domain1.com") || ([string tolower [HTTP::host]] equals "www.domain1.com") } {
HTTP::respond 301 Location http://domain2.com
}
elseif { ([string tolower [HTTP::host]] equals "domain3.com") || ([string tolower [HTTP::host]] equals "www.domain3.com")} {
HTTP::respond 301 Location https://domain3-edit.com
}
elseif { ([string tolower [HTTP::host]] equals "www.domain4.com") } {
HTTP::respond 301 Location http://domain4.com/
}
elseif { ([string tolower [HTTP::host]] equals "domain5.com") } {
HTTP::respond 301 Location https://domain5-edit.com/
}
elseif { ([string tolower [HTTP::host]] equals "www.domain6.com") } {
HTTP::respond 301 Location http://domain6.com/
}
elseif { ([string tolower [HTTP::host]] equals "www.domain7.com") } {
HTTP::respond 301 Location http://domain7.com/
}
elseif { ([string tolower [HTTP::host]] equals "domain7.com/security") } {
log local0. "Host before: [HTTP::host]"
HTTP::respond 301 Location http://domain7.com/ciso/pages/services.aspx
log local0. "Host after: [HTTP::host]" }
}
Thanks,
Bob
- hoolio
Cirrostratus
Hi Bob,when HTTP_REQUEST { switch "[string tolower [HTTP::host]]" { "domain1.com" - "www.domain1.com" { HTTP::respond 301 Location "http://domain2.com } "domain3.com" - "www.domain3.com" { HTTP::respond 301 Location "https://domain3-edit.com } "www.domain4.com" { HTTP::respond 301 Location "http://domain4.com/" } "domain5.com" { HTTP::respond 301 Location "https://domain5-edit.com/" } "www.domain6.com" { HTTP::respond 301 Location "http://domain6.com/" } "www.domain7.com" { HTTP::respond 301 Location "http://domain7.com/" } "domain7.com" { if {[string tolower [HTTP::uri]] eq "/security"}{ HTTP::respond 301 Location "http://domain7.com/"ciso/pages/services.aspx } } } }
- Bob_10976
Nimbostratus
Aaron...Thanks for the quick response and that is much cleaner then what I've been doing. It worked like a charm. I'm going to be looking at some other iRules I got and see about cleaning them up as well. This way seems much easier to maintain.. - Bob_10976
Nimbostratus
I forgot to ask, and I'm sure I can do this a couple of ways but since were being so clean I'd like to keep it that way. - hoolio
Cirrostratus
Here is a set of TCL man pages for the 8.4 version of TCL current iRules are based on:when HTTP_REQUEST { switch "[string tolower [HTTP::host]]" { "domain1.com" - "www.domain1.com" { HTTP::respond 301 Location "http://domain2.com } "domain3.com" - "www.domain3.com" { HTTP::respond 301 Location "https://domain3-edit.com } "www.domain4.com" { HTTP::respond 301 Location "http://domain4.com/" } "domain5.com" { HTTP::respond 301 Location "https://domain5-edit.com/" } "www.domain6.com" { HTTP::respond 301 Location "http://domain6.com/" } "www.domain7.com" { HTTP::respond 301 Location "http://domain7.com/" } "domain7.com" { switch -glob "[string tolower [HTTP::uri]]" { "/security" { "/security/" - Exact match for "/security" or "/security/" HTTP::respond 301 Location "http://domain7.com/ciso/pages/services.aspx" } "/urib*" { URI starts with "/urib" HTTP::respond 301 Location "http://domain7.com/ciso/pages/urib.aspx" } "*uric" { URI ends with "uric" HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx" } "*uri[d-f]" { URI ends with "urid", "urie" or "urif" HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx" } "*uri?" { URI ends with "uri" and any other character (which hasn't already been matched like b, c, d-f) HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx" } } } "www.domain8.com" { HTTP::respond 301 Location "http://domain8.com/" } default { Take some default action? } } }
- Bob_10976
Nimbostratus
Wow..sweet, I did actually get it to work using elseif statements, but I like how you've done this. The only question I have is how do you break out of the -glob flag. Is it as simple as what I did when I added domain8.com at the bottom, or should I adding those type of domains before the -glob flag? - Bob_10976
Nimbostratus
Not sure how you get the rule in there with all the formatting in place but I can't seem to figure that one out..sorry it so flat, I'm sure that doesn't make it any easier for you to read... - hoolio
Cirrostratus
I added a domain8 and a default case to the post above. - Hey bob, check out the iRules wiki on "switch" I found it to be a little more reader friendly as they apply situations to the F5...
- Bob_10976
Nimbostratus
Thanks a lot for the help on this, I really appreciate it!
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