Debugging Mod Rewrite

email-addthis printer-addthis favorites-addthis facebook-addthis digg-addthis | Share

03 May 2010 06:37:05
Category: PHP Development

I wish some had showed me this along time ago. Anyone who has had to deal with the mystery of "What the hell is mod rewrite doing?" or have just started learning mod rewrite will appreciate this.

Add this to your vhost -- obviously not for production.

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

That will give you nice feed back like this.

applying pattern '^/blogs/([^/\.]+)?/?([^/\.]+)?/?$' to uri '/blogs/view/164'
rewrite '/blogs/view/164' -> '/blogs.php?mode=view&blog_id=164'
split uri=/blogs.php?mode=view&blog_id=164 -> uri=/blogs.php, args=mode=view&blog_id=164

There you go then all you have to do is learn regex.