Forum Moderators: phranque

Message Too Old, No Replies

What do I find out what is stored in a variable inside .htaccess?

Specifically in a RewriteCond %{variable}

         

whitenoise

4:04 pm on Jun 26, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm trying to construct some code using mod_rewrite but am finding it very difficult since I don't know what is being recorded. In PHP (for example) I can echo variables to the screen to see if my code is correct, and where I need to make tweaks.

I can't seem to do this using mod_rewrite - its frustrating! I am doing a RewriteCond %{REQUEST_URI} (expression) and I want to know what it is getting, so I can refine my regular expression.

I've tried doing RewriteLog "/path/rewrite.log" etc but this causes Error 500. Does this file need to already exist?

Sorry if these are really basic questions but trying to learn!

jdMorgan

5:46 pm on Jun 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A quick-and-dirty method is to redirect to a test page, but with the variables appended as querry string parameters. Example:

RewriteRule ^foo\.html$ /bar.html?HTTP_HOST=%{HTTP_HOST}&REQUEST_URI=%{REQUEST_URI} [R=301,L]

Another way you could do it is to put server-side includes on an HTML page, and have that page print the variables. Example:

<p>HTTP_Host: <!--#echo var="HTTP_HOST" -->
<br>Request_URI: <!--#echo var="REQUEST_URI" --></p>

PHP and PERL can also be used, as you noted.

Jim

whitenoise

8:53 am on Jun 27, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks again for your help, it's appreciated.

g1smd

9:22 pm on Jun 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



More than once I have had a rule that worked for expected inputs, but which didn't do what I wanted for unexpected inputs.

Maybe I noticed while looking through code many weeks later, or maybe I found it as a result of some garbage in the server logs.

Whatever. Do as much testing as you can. It will pay off in having a more reliable site.