Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging mod_rewrite

I'm playing around with Apache's mod_rewrite module, and want to know if there is a decent way to output some debugging information? For example, the documentation lists a number of variables available:

%{HTTP_USER_AGENT}, %{HTTP_REFERER}, %{HTTP_COOKIE} ... etc

Is there a way I could output these just to see what I'm working with? I set up the RewriteLog (Level 2) and have been looking at that, but it'd be nice to be able to see the value of the variables.

like image 655
nickf Avatar asked Dec 31 '25 04:12

nickf


1 Answers

The HTTP_ variables come from HTTP headers, so you can print them using server side scripting, as with most of the other variables. For special variables, you can capture their values in a RewriteCond and append that to the query string.

RewriteCond RF=%{REQUEST_FILENAME}&API=%{API_VERSION} (.*)
RewriteRule ... ...?%1 [QSA]

To debug rewrite rules, I've found it helpful to run a virtual host solely for this purpose.

like image 118
outis Avatar answered Jan 02 '26 21:01

outis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!