Tips for debugging .htaccess rewrite rules

后端 未结 16 3177
萌比男神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:58

    Make sure that the syntax of each Regexp is correct

    by testing against a set of test patterns to make sure that is a valid syntax and does what you intend with a fully range of test URIs.

    See regexpCheck.php below for a simple script that you can add to a private/test directory in your site to help you do this. I've kept this brief rather than pretty. Just past this into a file regexpCheck.php in a test directory to use it on your website. This will help you build up any regexp and test it against a list of test cases as you do so. I am using the PHP PCRE engine here, but having had a look at the Apache source, this is basically identical to the one used in Apache. There are many HowTos and tutorials which provide templates and can help you build your regexp skills.

    Listing 1 -- regexpCheck.php

    Regexp checker
     

     

    " />

     

        \$$i"; echo "\n"; for( $i=0; $i<$a_ntests; $i++ ){ echo ''; foreach ($res[$i] as $v) { echo '';} echo "\n"; } ?>
    Test Vector    Result
         ',htmlentities($v, ENT_QUOTES,"UTF-8"),'   

提交回复
热议问题