Forum Discussion
Sam_Parkes_1110
Nimbostratus
Dec 01, 2006404 redirect based on URI
Hi,
I'm having trouble getting this iRule to work, just needs a simple redirect if a 404 is received but only if a specific URI is requested, I'm pretty new to this so sorry if it simple. What am I doing wrong?:
when HTTP_REQUEST {
[HTTP::uri] contains "folder/folder2"
}
when HTTP_RESPONSE {
if { [HTTP::status] contains "404"} {
HTTP::redirect "http://www.mysite.com/"}
}
Thanks,
- You'll want to store the URI in a session varaible and then access it in the response. I'm not sure what you were getting at with the comparison in the HTTP_REQUEST event without an if around it...
when HTTP_REQUEST { set the_uri [HTTP::uri] } when HTTP_RESPONSE { if { ([HTTP::status] equals "404") && ($the_uri equals "/folder/folder2") } { HTTP::redirect "http://www.mysite.com" } }
- Sam_Parkes_1110
Nimbostratus
Many thanks to you Joe - this is working perfectly now. - No problem and glad to help!
- MrVJTod_64267
Nimbostratus
I have an almost identical code blockwhen HTTP_REQUEST { set uri [string tolower [HTTP::uri]] set host [HTTP::host] } when HTTP_RESPONSE { if {([HTTP::status] equals 404) and ($uri equals "/fnf.asp")} { log local0. "404 : http://$host$uri" HTTP::respond 302 Location "http://$host" } }
telnet {bigip.ip} 80 GET /fnf.asp HTTP/1.0 HOST: {fqdn} Connection closed by foreign host.
- L4L7_53191
Nimbostratus
Odd - this rule works for me ver batum: - MrVJTod_64267
Nimbostratus
I can dig it. I don't understand why it's not working either. - MrVJTod_64267
Nimbostratus
could be a bug. it seems like one to me. - L4L7_53191
Nimbostratus
Great work and thanks for the excellent description. I'm sure you've already done this, but please be sure and get this information into the case!
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