Tips for debugging .htaccess rewrite rules

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

    (Similar to Doin idea) To show what is being matched, I use this code

    $keys = array_keys($_GET);
    foreach($keys as $i=>$key){
        echo "$i => $key 
    "; }

    Save it to r.php on the server root and then do some tests in .htaccess
    For example, i want to match urls that do not start with a language prefix

    RewriteRule ^(?!(en|de)/)(.*)$ /r.php?$1&$2 [L] #$1&$2&...
    RewriteRule ^(.*)$ /r.php?nomatch [L] #report nomatch and exit
    

提交回复
热议问题