Tips for debugging .htaccess rewrite rules

后端 未结 16 3141
萌比男神i
萌比男神i 2020-11-21 05:17

Many posters have problems debugging their RewriteRule and RewriteCond statements within their .htaccess files. Most of these are using a shar

16条回答
  •  时光说笑
    2020-11-21 05:41

    Regarding 4., you still need to ensure that your "dummy script stub" is actually the target URL after all the rewriting is done, or you won't see anything!

    A similar/related trick (see this question) is to insert a temporary rule such as:

    RewriteRule (.*) /show.php?url=$1 [END]
    

    Where show.php is some very simple script that just displays its $_GET parameters (you can display environment variables too, if you want).

    This will stop the rewriting at the point you insert it into the ruleset, rather like a breakpoint in a debugger.

    If you're using Apache <2.3.9, you'll need to use [L] rather than [END], and you may then need to add:

    RewriteRule ^show.php$ - [L]
    

    At the very top of your ruleset, if the URL /show.php is itself being rewritten.

提交回复
热议问题