Given the following Apache rewrite rule:
RewriteRule .* foo
...how do I find out precisely what string .* is testing against? Assume that any number of arbitrary rewrite rules could have been applied before this point, and that I have no way of knowing what they are (assume httpd.conf is hidden from me).
EDIT: Thanks, though keep in mind that I do not have access to edit (or even read!) httpd.conf. I only have .htaccess files at my disposal.
EDIT: removed solution that needed httpd.conf access
This will work, just put it on the line before your rewrite rule:
Then in a .ssi or .cgi file, output that variable.
Attempts to look at other variables won't necessarily tell you what your rule is matching against; they'll tell you what was matched against before any rewrite rules ran or what things look like after all the rewrite rules ran.
mod_rewrite uses regular expressions to identify a particular string and then rewrites that match with the replacement given. In the case of your example:
mod_rewrite will match any character (that's what the "." stands for), as many times as it repeats (thus the "*"). Now, since "*" is repeating ".", this means that it is going to match any string with any characters of any combination and length. Then, it's going to replace that big, long any with "foo".
So to use mod_rewrite, you need to have at least a basic understanding of regular expressions, as well as a full understanding of what it is you want to match and rewrite it as.
I often use a small program like Reggy or Kiki to help me layout my regular expression. You may find this helpful as well.
I hope this helps.
If you had access to httpd.conf, this answer describes how to turn on logging for mod_rewrite, which will give you exactly what you want.
If you have access to the .htaccess file in the file system being served, you can make the config changes there to activate logging.
Otherwise, Trial and error may be your best bet!
I know this is a header in IIS, I don't know about Apache, but the header UNENCODED_URL or HTTP_URL might give you the server-side URL if you query it in your server-side script (ASP/PHP/whatever).
You can then use that to back-track the rule in the .htaccess