---
title: "htaccess rewrite useragent"
date: "2013-07-10"
path: "/151-htaccess-rewrite-useragent.html"
section: "/ramblings"
aliases:
  - "/151"
  - "/151-htaccess-rewrite-useragent"
  - "/151.html"
  - "/ramblings/151-htaccess-rewrite-useragent.html"
---

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)"
```
