This is a case of "ask a question and answer it myself", which I'm posting for the benefit of anyone who has the same problem.
I had some problems debugging a mod_rewrite ruleset in a .htaccess file on a shared server, where I couldn't even access the Apache error logs. I found a neat way to debug them, which is this:
Write a short script that simply prints out it's querystring variables. e.g. in PHP:
<?='<pre>',htmlentities(print_r($_GET,true)),'</pre>'?>
is all you need.
Let's say you name this script "show.php" and put it in /public_html. Then in your .htaccess file, identify the point in your ruleset that you think might be causing the problem, and insert this rule:
RewriteRule (.*) /show.php?url=$1 [END]
The effect is the same as inserting a PRINT statement in a regular program. It'll let you know that (a) You reached that point in the ruleset, and (b) what the current rewritten URL is.
It's not as flash as a real debugging tool, but it gets the job done.
If you're using Apache <2.3.9, you'll have to use [L]
instead of [END]
. In that case, something to look out for is that your ruleset should not attempt to rewrite "/show.php" to anything else. If that's a problem, you can fix it by adding this rule at the very top:
RewriteRule ^show.php$ - [L]
...Just remember to remove it when you're done debugging!
Other possibility:
use this online htaccess tester:
http://htaccess.madewithlove.be/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With