Forum Discussion
veredgf_96123
Mar 31, 2019Nimbostratus
need to exclude certain files
Hi, I have an IRULE that sends people to a 404 page when there is a violation of "illegal URL".
Now I was given a second request that I should exclude all URLs leading to PDF files and instead redi...
Rico
Mar 31, 2019Cirrus
Seems like the easiest way to do this would be to add in a second variable that keeps track of if the file that is being requested is a pdf, if I am understanding your requirements correctly. I have not tested this iRule but I believe it should look something like this.
when HTTP_REQUEST {
set asm_404_not_found 0
if { [HTTP::uri] ends_with ".pdf"} {
set pdf_requested 0
}
}
when ASM_REQUEST_BLOCKING
{
set asm_info [ASM::violation_data] Any response tweaking should only be done in blocking mode!!!
if {[string compare [ASM::status] "blocked"] == 0} {
if {[string first {VIOLATION_OBJ_DOESNT_EXIST} [lindex $asm_info 0]] != -1} {
set asm_404_not_found 1
if {[info exists pdf_requested]} {
set pdf_requested 1
} else {
ASM::disable
TCP::close
}
}
}
}
when HTTP_RESPONSE_RELEASE {
if {$asm_404_not_found == 1} {
if{$pdf_requested == 1} {
HTTP::respond 301 Location "https://www.site.com/otherpage.aspx"
} else {
HTTP::respond 301 Location "https://www.site.com/404.aspx"
}
}
}
For future reference, you can put formatted code into devcentral without an issue if you put "~~~" above and below the code you want.
Hope this helps. If you have any more questions, I am sure I can help.
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