htaccess rewrite useragent

Written by Peter Davies on .

This is a simple way to redirect any requests to an error page given the user-agent (browser). In this example we had a rogue XML-RPC python application causing havoc on a magento store, so we needed a quick way of reducing the requests and then the subsequent load on the server.

RewriteCond %{HTTP_USER_AGENT} .*python.* [NC]
RewriteRule .* - [R=503]

This then shows up in the "access_log" with a 503 error page:

123.123.123.123 - - [10/Jul/2013:12:46:45 +0100] "POST /api/xmlrpc HTTP/1.1" 503 236 "-" "xmlrpclib.py/1.0.1 (by www.pythonware.com)"