https://bz.apache.org/bugzilla/show_bug.cgi?id=64526

            Bug ID: 64526
           Summary: InheritDownBefore won't keep vhost-context rules from
                    re-executing after per-dir rules
           Product: Apache httpd-2
           Version: 2.4.41
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: mod_rewrite
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

A web application depends on htaccess rules (which may also be `Include`d for
performance reasons), mainly to set its entry-point.

I want to strip some query parameters and avoid making specific assumptions
about application's particular "routing" (htaccess).


Example:

```
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/foo

    LogLevel rewrite:trace8

    RewriteEngine On
    RewriteOptions InheritDownBefore

    # Strips utm_* parameters
    RewriteCond %{QUERY_STRING}
(.*)(?:^|&)(?:utm_(?:source|medium|campaign|term|content)|v|ver|rev)=(?:[^&]*)((?:&|$).*)
    RewriteCond %1%2 (^|&)([^&].*|$)
    RewriteRule ^(.*)$ $1?%2 [N]

    <Directory "/var/www/foo">
        Require all granted
        # Written here for clarity, but could be within a htaccess
        # echo ok > /var/www/foo/bar.php
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/bar\.php
        RewriteRule .* bar.php [L]
    </Directory>
</VirtualHost>
```

Expected:
- [vhost] strip utm_* parameters
- [per-dir] redirect (internal) from * to bar.php

Actual:
- [vhost] strip utm_* parameters
- [per-dir] redirect (internal) from * to bar.php
- [vhost] strip utm_* parameters
- [per-dir] redirect (internal) from bar.php to bar.php


Note:
- InheritDownBefore typical use is when directory-rules can't be changed. Using
[END] instead of [L] is not an option. (In my case it's an actual htaccess I
`Include`)

Aggravating factor:
- [NS] flag to the vhost-context utm_* stripper rule WON'T keep rule from
re-executing.

Workaround:
- RewriteRule ^/bar\.php - [S=1]
# To insert just after "RewriteOptions InheritDownBefore" in the above example.
# But this implies previous knowledge of the entry point filename.


Somehow related problem:
With the above example, if "/" is reached, per-dir rules are not processed at
all, probably because "/" exists on the filesystem what leads to a 403 before
per-dir rules get a change to be executed.

Stated another way:
If a virtual-host's rule is executed, even if the REQUEST_URI is left 
unchanged, per-dir rules won't be considered.

As such, I've found no other way to force the per-dir rewrite process to keep
going other than... artificially redirecting '/' to a non-existing path.
Eg:
`RewriteRule / /___not_exists` (as a final rule in the vhost-context rule).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to