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 ?

link|improve this question

feedback

2 Answers

up vote 2 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="http://www.example.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST}">http://www.example.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST}</a> [R=301,L,QSA]
link|improve this answer
feedback

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! :)

link|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
feedback

Your Answer

 
or
required, but never shown

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