Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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]
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 Jul 2 '13 at 4:31

Your Answer

 
discard

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.