views:

210

answers:

3

I have the following in a .htaccess file as a test:

RewriteEngine on
RewriteRule ^(.*)$ /backend/$1

This works as expected. I was able to get rewrite logging working with the following in apache2.conf:

<IfModule mod_proxy.c>
    RewriteLog "/tmp/REWRITE.log"
    RewriteLogLevel 9
</IfModule>

The log file is created and logs debug info as expected. However, when I delete the .htaccess file, change the apache2.conf directive as follows, and restart apache to do the equivalent globally, it doesn't work.

<IfModule mod_proxy.c>
    RewriteLog "/tmp/REWRITE.log"
    RewriteLogLevel 9
    RewriteEngine on
    RewriteRule ^(.*)$ /backend/$1
</IfModule>

I'm using Apache/2.0.55 on Ubuntu.

Help!

A: 

Have you considered turning RewriteEngine on before any other rewrite directives?

PP
Good idea, I did not consider it. However, I moved `RewriteEngine on` to be first before `RewriteLog "/tmp/REWRITE.log"`, restarted apache, and the result is still the same :(
Robert
A: 

Are your RewriteRule directives contained within a particular server definition? Do you have virtual servers at work?

The reason I ask this is that you say this works in an .htaccess file which is directory specific; although officially the documentation says that RewriteRule can apply to server config, virtual host, directory, .htaccess.

PP
Thanks for your help. It's a virtual server in the sense that it is a VPS that I pay for monthly (Xen). The RewriteRule works when I put it in `/var/www/public/<some-directory>/.htaccess` as shown in the first example and it doesn't work when I put it in `/etc/apache2/apache2.conf` as shown in the last example (even when I turn the RewriteEngine on first). The goal is not to use .htaccess files at all - I want to define some RewriteRules globally.
Robert
I'm sorry I can't be more helpful. With a lot of these things it is trial-and-error. It's possible the RewriteRule doesn't apply globally so easily, but if you were to put it in the <Directory> block of your top-level directory is it possible it would apply to all sub-directories..
PP
A: 

Have you tried this ?

    RewriteEngine on
    RewriteRule ^(.*)$ /backend/$1

<IfModule mod_proxy.c>
    RewriteLog "/tmp/REWRITE.log"
    RewriteLogLevel 9

</IfModule>

Because this way I was able to do rewriting, but log didnt worked hence a issue in mod_proxy.c

v1shAl