How to echo out from .htaccess?

Solution 1:

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

Solution 2:

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 (.*) http://www.example.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST} [R=302,L,QSA]

Solution 3:

Here is an interesting little hack to "echo" out variables from an .htaccess file.

If you have AllowOverride set to FileInfo you can set and trigger a custom error response in your .htaccess file with the desired variables in the output:

ErrorDocument 404 "Request: %{THE_REQUEST} Referrer: %{HTTP_REFERER} Host: %{HTTP_HOST}"
RewriteRule ^ - [L,R=404]

Depending on how creative you are with expressions you can output quite alot of useful information!

You are not limited to using the 404 status on your "echoed" content. You can even override the status 200 "ErrorDocument"--which coupled with <If> directives could make for some other pretty interesting uses of this hack to return content directly from an .htaccess file.

Tags:

.Htaccess