mod_rewrite directives in <Location> section confusingly disable rewrites in .htaccess

Bug #711465 reported by Daniel Richard G.
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apache2 (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

Binary package hint: apache2.2-bin

Reporting this against version 2.2.16-1ubuntu3.1 in Maverick.

I have apache2 configured in the following way:

1. mod_rewrite is enabled;

2. "AllowOverride All" is set (on /var/www) to enable the use of .htaccess files;

3. "RewriteEngine On" plus some basic rewrite rules are placed in /var/www/.htaccess .

This works. URLs are rewritten without issue. But then, if I add the following to the server config, say in /etc/apache2/httpd.conf ...

    <Location />
        RewriteEngine On
    </Location>

...then the rewrites stop working. There is no indication of why, no error or warning message given even with logging/debugging turned up to maximum---just .htaccess rewrite rules that refuse to work despite everything else seemingly in order. You get the same result if you have a RewriteRule directive in the <Location> section; it appears that any reference to a mod_rewrite directive therein leads to this situation.

This led to a lot of frustration on my part, because before I figured out that I had to change AllowOverride to get .htaccess files working, I tried adding mod_rewrite directives in a <Location> setting, and left them in, figuring they would be harmless at most.

After figuring out what was going on, I noticed that the mod_rewrite documentation states the following: "Although rewrite rules are syntactically permitted in <Location> and <Files> sections, this should never be necessary and is unsupported."

I think it would be helpful if mod_rewrite were to give a prominent warning or error if it is invoked in a <Location> (or <Files>) section, rather than behaving in the above-described confusing and undocumented manner.

Revision history for this message
Stefan Fritsch (sf-sfritsch) wrote :

I think you were only missing "RewriteOptions inherit". Without that, only the "last" set of RewriteRules are executed, and Location comes after .htaccess. Can you try that?

Revision history for this message
Daniel Richard G. (skunk) wrote :

Adding "RewriteOptions inherit" doesn't seem to have any effect, whether in the <Location> section or the .htaccess file.

Besides, looking at the documentation... "inherit - This forces the current configuration to inherit the configuration of the parent. In per-virtual-server context, this means that the maps, conditions and rules of the main server are inherited. In per-directory context this means that conditions and rules of the parent directory's .htaccess configuration are inherited."

Doesn't that mean that the inheritance goes from main server to virtual server, and parent directory to subdirectory? (In other words, I don't see why it would be the .htaccess rewrite rules that would be discarded, if any...)

Revision history for this message
Scott Moser (smoser) wrote :

Thank you for taking the time to open a detailed bug report. As I understand
The most likely path to getting your issue resolved is to report it upstream https://issues.apache.org/bugzilla/ .

Changed in apache2 (Ubuntu):
importance: Undecided → Wishlist
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.