How to debug Apache mod_rewrite

后端 未结 5 1304
不思量自难忘°
不思量自难忘° 2020-11-22 04:56

I have two main problems with mod_rewrite:

1) There is no meaningful error reported when I have an invalid rule

相关标签:
5条回答
  • 2020-11-22 05:14

    The LogRewrite directive as mentioned by Ben is not available anymore in Apache 2.4. You need to use the LogLevel directive instead. E.g.

    LogLevel alert rewrite:trace6
    

    See http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#logging

    0 讨论(0)
  • 2020-11-22 05:14

    There's the htaccess tester.

    It shows which conditions were tested for a certain URL, which ones met the criteria and which rules got executed.

    It seems to have some glitches, though.

    0 讨论(0)
  • 2020-11-22 05:17

    For basic URL resolution, use a command line fetcher like wget or curl to do the testing, rather than a manual browser. Then you don't have to clear any cache; just up arrow and Enter in a shell to re-run your test fetches.

    0 讨论(0)
  • 2020-11-22 05:23

    Based on Ben's answer you you could do the following when running apache on Linux (Debian in my case).

    First create the file rewrite-log.load

    /etc/apache2/mods-availabe/rewrite-log.load

    RewriteLog "/var/log/apache2/rewrite.log"
    RewriteLogLevel 3
    

    Then enter

    $ a2enmod rewrite-log

    followed by

    $ service apache2 restart

    And when you finished with debuging your rewrite rules

    $ a2dismod rewrite-log && service apache2 restart

    0 讨论(0)
  • 2020-11-22 05:33

    One trick is to turn on the rewrite log. To turn it on,try these lines in your apache main config or current virtual host file (not in .htaccess):

    RewriteEngine On
    RewriteLog "/var/log/apache2/rewrite.log"
    RewriteLogLevel 3
    

    Since Apache httpd 2.4 mod_rewrite RewriteLog and RewriteLogLevel directives has been completely replaced by the new per-module logging configuration.

    LogLevel alert rewrite:trace6
    
    0 讨论(0)
提交回复
热议问题