Forum Discussion
Dayton_Gray_103
Nimbostratus
Oct 18, 2006Limiting connections base on user-agent and URI
I am wondering if anyone has an examples or can point me in the right direction as to how I would go about limiting connections based on the HTTP::header User-Agent and based on HTTP::uri. I'm basical...
Oct 18, 2006
You can get at the User-Agent with the HTTP::header "User-Agent" command and the URI with the HTTP::uri command. You can then issue a redirect with the "HTTP::redirect" command (I'm assuming you are doing a HTTP redirect since that's what you stated. I'm not sure with the RewriteRule does with Apache. At first glance it would seem to rewrite the URI as it sends it to the backend server. If this is the case, then you'll want to use the HTTP::uri command to modify the URI. If you do want a true redirect sent do the browser you'll want the HTTP::redirect command
Here's a first stab.
when HTTP_REQUEST {
step 1
RewriteRule ^/(.*\.shtml)$ http://me.you.com/$1 [P]
switch -glob [HTTP::uri] {
"*.shtml" {
For a full HTTP redirect
HTTP::redirect "http://me.you.com/"
-or- if you just want to modify the request to the server
HTTP::header replace "Host" "me.you.com"
HTTP::uri "/"
}
}
step 2
RewriteCond User-Agent: .*(?:Googlebot|msnbot|Slurp|Ask\sJeeves|Inktomi|Yahoo).*
RewriteRule ^/$ http://me.you.com/ [P]
RewriteCond User-Agent: .*(?:Googlebot|msnbot|Slurp|Ask\sJeeves|Inktomi|Yahoo).*
RewriteRule ^/index.jsp.* http://me.you.com/ [P]
switch -glob [string tolower [HTTP::header "User-Agent"]] {
"*googlebot*" -
"*msnbot*" -
"*slurp*" -
"*ask jeeves*" -
"*inktomi*" -
"*yahoo*" {
switch -glob [string tolower [HTTP::uri]] {
"/" -
"/index.jsp*" {
HTTP::redirect "http://me.you.com/"
}
}
}
}
}
You could have just have easily used if/elseif's but I tend to favor switch statements for their readability.
Hope this helps...
-Joe
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