Forum Discussion
Edgar_Palamarch
Nimbostratus
Jul 05, 2012Referer Based Redirect
Hello,
A former client is leaching images from our website. So, I need to redirect/block requests coming from them based on the referer header. Found a couple sample codes, but couldn't make...
nitass
Employee
Jul 06, 2012yes, you can use data group and class command.
class wiki
https://devcentral.f5.com/wiki/irules.class.ashx
e.g.
[root@ve10:Active] config b class badreferer_class list
class badreferer_class {
{
"BadReferer.com"
"badman.com"
}
}
[root@ve10:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
set referrer_host [URI::host [HTTP::header value Referer]]
log local0. "\[HTTP::uri\]: [HTTP::uri]"
log local0. "\[HTTP::header value Referer\]: [HTTP::header value Referer]"
log local0. "\[URI::host [HTTP::header value Referer]\]: [URI::host [HTTP::header value Referer]]"
if { [class match -- $referrer_host equals badreferer_class] } {
HTTP::redirect http://BadReferer.com/image.jpg
}
}
}
[root@ve10:Active] config curl -I http://172.28.19.79 -H "Referer: http://BadReferer.com/something"
HTTP/1.0 302 Found
Location: http://BadReferer.com/image.jpg
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
[root@ve10:Active] config curl -I http://172.28.19.79 -H "Referer: http://badman.com/something"
HTTP/1.0 302 Found
Location: http://BadReferer.com/image.jpg
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
[root@ve10:Active] config tail /var/log/ltm
Jul 6 09:05:15 local/tmm info tmm[5111]: Rule myrule : [HTTP::uri]: /
Jul 6 09:05:15 local/tmm info tmm[5111]: Rule myrule : [HTTP::header value Referer]: http://BadReferer.com/something
Jul 6 09:05:15 local/tmm info tmm[5111]: Rule myrule : [URI::host http://BadReferer.com/something]: BadReferer.com
Jul 6 09:05:20 local/tmm info tmm[5111]: Rule myrule : [HTTP::uri]: /
Jul 6 09:05:20 local/tmm info tmm[5111]: Rule myrule : [HTTP::header value Referer]: http://badman.com/something
Jul 6 09:05:20 local/tmm info tmm[5111]: Rule myrule : [URI::host http://badman.com/something]: badman.com
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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