Roll your own Apache Rewrite Log
Note to self: Here is the .htaccess code for creating an Apache Rewrite log. This is definitely helpful for testing .htaccess rewrite rules, permalinks, etc. Update: as jc points out in the comments section, Apache versions 2.2 or better no longer allow RewriteLog directives in htaccess files. For these versions, it is necessary to coordinate logging through the server configuration file or via virtual host. For more information, check the source. For pre-2.2 versions of Apache, continue reading to learn how to Roll your own Apache Rewrite Log!
via http.conf
Twist one up via the Apache configuration file by placing this code at the foot of your http.conf (remember to edit the path):
# Roll your own Rewrite log
# Log details via scale of 1 to 9
# 1 = few details, 5 = enough details, 9 = too much detail
RewriteEngine On
RewriteLog "/absolute/path/to/your/wwwroot/public_html/rewrite.log"
RewriteLogLevel 5
via htaccess
Roll one tuf via your site’s root .htaccess by placing this code at the end of the file (remember to edit the path):
# Roll your own Rewrite log
# Log details via scale of 1 to 9
# 1 = few details, 5 = enough details, 9 = too much detail
RewriteEngine On
RewriteLog "/absolute/path/to/your/wwwroot/public_html/rewrite.log"
RewriteLogLevel 5
Example
Here is an example indicating the type of data logged by the RewriteLog directive:
64.246.32.000 - [07/July/2007:07:07:07 - 0700] [example.com/sid#80077333][rid#800b7a33/initial] (2) init rewrite engine with requested uri /press/wp-comments-post.php
64.246.32.000 - [07/July/2007:07:07:07 - 0700] [example.com/sid#80077333][rid#800b7a33/initial] (2) rewrite /press/wp-comments-post.php -> http://64.246.32.000/
64.246.32.000 - [07/July/2007:07:07:07 - 0700] [example.com/sid#80077333][rid#800b7a33/initial] (2) explicitly forcing redirect with http://64.246.32.000/
64.246.32.000 - [07/July/2007:07:07:07 - 0700] [example.com/sid#80077333][rid#800b7a33/initial] (1) escaping http://64.246.32.000/ for redirect
64.246.32.000 - [07/July/2007:07:07:07 - 0700] [example.com/sid#80077333][rid#800b7a33/initial] (1) redirect to http://64.246.32.000/ [REDIRECT/301]
Related articles
- Stupid htaccess Trick: Enable File or Directory Access to Your Password-Protected Site
- Permanently Redirect a Specific IP Request for a Single Page via htaccess
- How to Enable PHP Error Logging via htaccess
- Building the 3G Blacklist, Part 1: Improving Site Security by Recognizing and Exploiting Server Attack Patterns
- Building the 3G Blacklist, Part 2: Improving Site Security by Preventing Malicious Query-String Exploits
- Building the 3G Blacklist, Part 3: Improving Site Security by Selectively Blocking Rogue User Agents
- Building the 3G Blacklist, Part 4: Improving the RedirectMatch Directives of the Original 2G Blacklist
About this article
This is article #249, posted by Perishable on Tuesday, November 28, 2006 @ 12:13pm. Categorized as Function, and tagged with apache, htaccess, log, mod_rewrite, statistics, tips, tutorial. Updated on April 30, 2008. Visited 14938 times. 2 Responses »
Bookmark • Trackback • Comment • Subscribe • Explore
« Launch Multiple Programs with One Click • Up • Auto-Focus Form Elements with JavaScript »
1 • April 30, 2008 at 12:58 am — jc says:
Don’t know which version of apache you use, but apache 2.2 does not allow rewritelog in .htaccess files.