Hello,

In both Apache 2.2 and 2.4, I get strange behavior with <Location /foo>
directive and requested URL http://example.com/foo/non-existing.

Say my configuration is:

    <VirtualHost *:80>

        DocumentRoot "/var/www/apache.test"

        ServerName apache.test

        <Directory "/var/www/apache.test">

            Options Indexes FollowSymLinks

            AllowOverride None
            Order allow,deny

            Allow from all


            # Catch non-existing resources with index.php:
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [L]
            RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
            RewriteRule ^(.*) - [E=BASE:%1]
            RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]
        </Directory>



        <Location "/">

            Header set X-All "true"

        </Location>



        <Location "/foo">

            Header set X-Foo "true"

        </Location>

    </VirtualHost>


and DocumentRoot directory "/var/www/apache.test" has following content:

    /var/www/apache.test
    ├── bar
    │   └── baz
    ├── foo
    │   └── qux
    └── index.php

/foo directory physically exists in DocumentRoot and
directory /foo/non-existing does not.

Testing various URLs using:
curl -D - http://apache.test/ -o /dev/null -s | grep -F "X-"

I get the following results:

URL                    | X-All? | X-Foo?
-----------------------|--------|-------
/                      |      X |
/bar/                  |      X |
/bar/baz/              |      X |
/bar/non-existing/     |      X |
/non-existing/         |      X |
/foo/                  |      X |      X
/foo/qux/              |      X |      X
/foo/non-existing/     |      X |
/foo/qux/non-existing/ |      X |

I thought <Location "/foo"> would add an header for any request to
http://apache.test/foo/*.

I get <Directory> is for file system items and <Location> is for dynamic
URLs. So I also tried using both <Directory> and <Location> to cover all
cases:

    <VirtualHost *:80>
        DocumentRoot "/var/www/apache.test"
        ServerName apache.test

        <Directory "/var/www/apache.test">
            Options Indexes FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all

            # Catch non-existing resources with index.php:
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [L]
            RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
            RewriteRule ^(.*) - [E=BASE:%1]
            RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]

            Header set X-AllDir "true"
        </Directory>
        <Location "/">
            Header set X-AllLoc "true"
        </Location>

        <Directory "/var/www/apache.test/foo">
            Header set X-FooDir "true"
        </Location>
        <Location "/foo">
            Header set X-FooLoc "true"
        </Location>
    </VirtualHost>


I get the following results:

URL                    | X-AllDir? | X-AllLoc? | X-FooDir? | X-FooLoc?
-----------------------|-----------|-----------|-----------|----------
/                      |         X |         X |           |
/bar/                  |         X |         X |           |
/bar/baz/              |         X |         X |           |
/bar/non-existing/     |         X |         X |           |
/non-existing/         |         X |         X |           |
/foo/                  |         X |         X |         X |         X
/foo/qux/              |         X |         X |         X |         X
/foo/non-existing/     |         X |         X |           |
/foo/qux/non-existing/ |         X |         X |           |


I also tried only having a <Location> dedicated to "/foo/non-existing/":

    <VirtualHost *:80>
        DocumentRoot "/var/www/apache.test"
        ServerName apache.test

        <Directory "/var/www/apache.test">
            Options Indexes FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all

            # Catch non-existing resources with index.php:
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [L]
            RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
            RewriteRule ^(.*) - [E=BASE:%1]
            RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]
        </Directory>

        <Location "/foo/non-existing">
            Header set X-FooNonExisting "true"
        </Location>
    </VirtualHost>

But http://apache.test/foo/non-existing still won't return the
X-FooNonExisting header.

The way I see it, Apache somehow fails to match requests to
/foo/non-existing/ because asked asset is both for a existing directory
("/foo") and a virtual-subdir ("non-existing").

My ultimate goal is to set a given header in all the HTTP responses but
the ones answering requests to:
http://example.com/foo/qux/non-existing/*.


-- 
DUVERGIER Claude

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org

Reply via email to