简体   繁体   中英

mod_rewrite works in .htaccess files but not in apache2.conf

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!

您是否考虑过在其他任何重写指令之前打开RewriteEngine?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM