Forum Discussion
Brandon_11574
Mar 27, 2011Nimbostratus
Special 404 Redirect Rules
We have some sub folders in our site that we want special 404 handling. If there are any 404 errors on any file found under that folder or any of its children folders, we want to employ this 404 handling. This can easily be done with something like the following:
if { ([HTTP::status] contains "404") or ([HTTP::status] contains "400")} {
if { [HTTP::uri] starts_with "/$subFolder/" } {
HTTP::redirect http://domain.com/$subFolder/specialPage.aspx
}
}
But here's my dilemma. I have over 500 different sub folders that need to have this rule applied to. Is there a way to store the sub folder list into an array or similar type variable? We would like to simply maintain the 'array' and not worry about writing a large number of if statements. Or does anyone have a good way for us to comply with this 'requirement' with reasonably maintainable code?
- The_BhattmanNimbostratusHi Brandon,
- Michael_YatesNimbostratusSure. You can store them in a Data Group.
when HTTP_REQUEST { set targethost [HTTP::host] set targeturi [HTTP::uri] } when HTTP_RESPONSE { if { [HTTP::status] == 400 || [HTTP::status] == 404 } { if { [class match $targeturi starts_with mydatagroup ] } { HTTP::redirect "http://$targethost[URI::path $targeturi 1 1]specialPage.aspx" } } }
- Colin_Walker_12Historic F5 AccountThe class match example is where I'd go with this too. Keep in mind that if you want even more customization you could store the actual location of the specialized error pages in the class as well (since classes support key/value pairs) and pull them out for each request, allowing for more granular control.
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