Archive

Posts Tagged ‘RewriteRule’

How to trace .htaccess’ RewriteRule

Recently I’ve have had to debug the RewriteRules of my .htaccess (using Apache 2.2.20 version).

For me, the easisest way I’ve found to debug the RewriteRule is to edit /etc/apache2/sites-available/default and add this lines:


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

This lines can also be added to apache2.conf.

Now I can adjust RewriteLogLevel from 0 (no log) to 9 (logs almost everything). Don’t forget to read the Apache 2.2 documentation, as this may affect the server’s performance. To disable the rewrite log, adjust RewriteLogLevel to 0 instead of redirecting the RewriteLog to /dev/null, as the log is still created.

In my case, setting the RewriteLogLevel to 2 is enough to debug the rewrite rules, with this command:


tail -f /var/log/apache2/rewrite.log | grep rewrite

Advertisements

Plus sign in URL get parameter is received as a space

I’ve an URL like this:

http://www.example.com/example.php?page=one+two

My PHP script reads the page with $_GET([‘page’]), and the result is this, the plus sign is converted to an space:

one two

My server uses Apache/2.2.3 (CentOS) & PHP Version 5.2.14.
There’s an easy workaround using the [B] flag (escape backreferences) for mod_rewrite, as stated in the apache documentation:
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b
If I put the B flag to my RewriteRule I get this error:

RewriteRule: unknown flag 'B'

Because the B flag is available from apache version 2.2.7 onwards, so it’s the turn to update the apache server version!

Categories: apache, php Tags: , ,