Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We write a lot of code to htaccess but what is the best method to debug other than refreshing the page ?

Is there some way that I can write it out to a file ? or is there some echo/print function ?

Simply how do i know what my $1 $2 $3 is ?

share|improve this question
up vote 3 down vote accepted

You could try the method mentioned in blog post titled A Couple Ways to Debug mod_rewrite:

Basically what you do is dump some of the info that mod_rewrite is using back out into the headers then use the Firebug or LiveHTTP Headers extensions in Firefox to watch the headers and read your debug info.

In .htaccess use the condition and rule:

RewriteCond %{QUERY_STRING} !vardump
RewriteRule (.*) <a href="$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST}">$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST}</a> [R=301,L,QSA]
share|improve this answer

Try these:

RewriteLog "/myfolder/mylogfile.log" 
RewriteLogLevel 3

These are just Regular Expressions with some additions, so you can use Regex Coach for initial testing against URLs, or any other Regex debugging tools.

Cheers! :)

share|improve this answer
Very useful tool, but remember to remove it after debugging as your can get a massive log file! – Coops Nov 24 '09 at 10:22
Apparently this doesn't work in .htaccess files. It has to go in httpd.conf which means it's usually not achievable on shared hosting accounts. :-( – Simon East Jul 2 '13 at 4:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.