Forum Discussion
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 redirect them to a different page. I have been trying to combine this second redirect request with and ELSE option but so far am unsuccessful. Adding a second IRULE won't work.
This is my IRULE:
when HTTP_REQUEST {
set asm_404_not_found 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
ASM::disable
TCP::close
}
}
}
when HTTP_RESPONSE_RELEASE {
if {$asm_404_not_found == 1} {
HTTP::respond 301 Location "https://www.site.com/404.aspx"
}
}
Any ideas? (sorry for the horrible formatting)
Thanks,
Vered
- RicoCirrus
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
* 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