I have done lots of searching and have even come across posts of exactly what I want to do but is doesn’t seem to work for me. I’m wondering if I’m running into a problem because I’m running 9.4.4 but it seems simple enough.
Agency1 is getting a complete makeover and I want to redirect 404’s just for them to their own page.
Why doesn’t this rule work? (the 404 pages still show)
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
}
when HTTP_RESPONSE {
if { [HTTP::status] == 404 and $uri eq "/agency1"} {
HTTP::redirect "http://www.main.com/agency1/moved.html"
}
}
My only guess is that it never equals “agency1” if I remove the that part it redirect all 404’s from www.main.com which makes sense.
You probably want to add a * to the end of /agency1 to match paths starting with /agency1. Without the asterisk, it will only match on the exact /agency1 path.
Ok the wildcard on Wil’s code seems to do what I wanted it to.
if I’m directing to a real .html as in http://www.main.com/agency1/moved.html it won’t meet the condition 404 AND /agency1* right? I can say I don’t understand Wil’s code enough to know for sure but you all brought it up
Sorry to bug you but I’m thinking ahead and if agency2 finds out we are doing this for agency1, they are going to want it too. What is the most efficient way to do this for agency2 as well? or is just adding another irule with /agency2’s info good enough?
I’m always so nervous posting my newbie questions here and I’m always smiling at the at results, Thanks for all the help. One last question and I’ll try to answer it myself. I think you did pretty much answer it in the log example I just want to make sure its the right way to do this. Also if the statement is in the right place.
Scenario 3: Big boss says “we are doing this for the agencies, why can’t we return a generic moved.html for anything that doesn’t match /agency1 and /agency2?”
I’m sorry one more question. What if it was a vanity domain (controlled by host header) on the same VIP that I refer to above. would it work too? something like
Thanks for helping me under stand this. You are helping me with 2 issues now. I tried a variety of ways to make /agency2 a vanity domain but not having much luck Could I just get one more sample leaving /agency1 the way it is, agency2 is now www.agency2.com?
my other issue? yeah is it an iRule with 88 “if” statements in it. I’m hoping I can apply what I’m learning here to that.
oh I completely missed how you added the “$host” to the second part. That make sense except that I wouldn’t be matching /agency2 anymore. It would need to be a condition of 404 + host so I thought I would have to do another “switch”
I could just keep the vanity domains separate or just deal with them when someone requests it
I do have a test vip that mirrors production, I’m not going to add this to my huge redirect irule, just going to keep it separate. It seems to be happy that way. I’ll save my “whats the best way to handle a rule with 88 if statements in it” for another discussion as I have taken too much of your time already Thanks a bunch