How can I debug mod_rewrite rules?

后端 未结 2 641
情书的邮戳
情书的邮戳 2020-12-31 23:28

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

相关标签:
2条回答
  • 2020-12-31 23:50

    Other possibility:

    use this online htaccess tester:

    http://htaccess.madewithlove.be/

    0 讨论(0)
  • 2020-12-31 23:52

    Very helpful insight. For years I've been trying to figure out how to debug mod_rewrite rules without needing to have root access and having to put the rules in httpd.conf. This does it!

    You have one minor mistake in your PHP:

    <?='<pre>',htmlentities(print_r($_GET),true),'</pre>'?>
    

    In this code, print_r() outputs everything in $_GET to stdout and then returns the value true, which htmlentities() picks up as its first argument. htmlentities() also receives the literal true as its second argument, which is an optional argument that tells htmlentities() whether or not to mess with single- and/or double-quotes.

    I think what you intended was:

    <?='<pre>',htmlentities(print_r($_GET, true)),'</pre>'?>
    

    This tells print_r() to format everything in $_GET. Passing true as the second argument to print_r() tells it not to output the result to stdout, but instead to put the result in a string and return that string as print_r()'s return value. htmlentities() then receives that string as its one input parameter, and does appropriate substitutions to force the browser to display the string as is rather than allowing the browser to interpret the string. E.G. -

    <i>text</i>
    

    would get translated to:

    &lt;i&gt;text&lt;/i&gt;
    

    which will cause the browser to display:

    <i>text</i>
    

    instead of displaying the word "text" in italics:

    text

    0 讨论(0)
提交回复
热议问题