How to know which resources are called after using apache's http server's mod_rewrite.

March 2012.

The situation

You set up rewrite rules in your apache configuration.

RewriteEngine On
RewriteRule ^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ product.php?category=$1&product=$2 [NC,L]
RewriteRule ^blog/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ blog.php?what=$1&post=$2 [NC,L]

If you have a problem, you would like to be able to see what urls are really called (after the rewriting).


Create a new log file, containing only the requested URL and the rewrited one.

LogFormat "%r -> %f%q" rewriting
CustomLog /var/log/apache2/access_rewriting.log rewriting


GET /products/cake/kouignamann/ HTTP/1.1 -> /var/www/product.php?category=cake&product=kouignamann
GET /products/beverages/cider/ HTTP/1.1 -> /var/www/product.php?category=beverages&product=cider
GET /blog/life/4269/ HTTP/1.1 -> /var/www/blog.php?what=life&post=4269

You can then know which scripts are actually called, along with their arguments.