You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by DUVERGIER Claude <ht...@claude.duvergier.fr> on 2017/03/20 16:30:31 UTC
[users@httpd] and partially non-existing directory?
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
\u251c\u2500\u2500 bar
\u2502 \u2514\u2500\u2500 baz
\u251c\u2500\u2500 foo
\u2502 \u2514\u2500\u2500 qux
\u2514\u2500\u2500 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-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] and partially non-existing directory?
Posted by DUVERGIER Claude <ht...@claude.duvergier.fr>.
Le 20/03/2017 � 17:38, Eric Covener a �crit :
> On Mon, Mar 20, 2017 at 12:38 PM, Eric Covener <co...@gmail.com> wrote:
>> On Mon, Mar 20, 2017 at 12:30 PM, DUVERGIER Claude
>> Are you getting mixed up by looking at the headers for unsuccessful
>> requests but not telling mod_headers to 'always' set the header?
>>
>> The optional condition argument determines which internal table of
>> responses headers this directive will operate against. Despite the
>> name, the default value of onsuccess does not limit an action to
>> responses with a 2xx status code. Headers set under this condition are
>> still used when, for example, a request is successfully proxied or
>> generated by CGI, even when they have generated a failing status code.
>>
>
> http://httpd.apache.org/docs/2.4/mod/mod_headers.html#header
>
> (submitted too early)
>
> Location /foo should behave how you expect
>
>
During my tests, "always" condition didn't changed the results.
With:
<Location "/foo">
Header always set X-HeaderFooLoc "true"
</Location>
(and no other Header nor <Location> directive in the config)
(Or with "onsuccess" condition instead)
I get the header when requesting the following URLs:
* .../foo/
* .../foo/qux/
But not for .../foo/non-existing/
Forgot to say: tests were performed on v2.2.22 (Debian 7) and v2.4.18
(Ubuntu 16.04).
--
DUVERGIER Claude
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] and partially non-existing directory?
Posted by Eric Covener <co...@gmail.com>.
On Mon, Mar 20, 2017 at 12:38 PM, Eric Covener <co...@gmail.com> wrote:
> On Mon, Mar 20, 2017 at 12:30 PM, DUVERGIER Claude
> <ht...@claude.duvergier.fr> wrote:
>> <Location "/foo">
>>
>> Header set X-Foo "true"
>>
>> </Location>
>
>
> Are you getting mixed up by looking at the headers for unsuccessful
> requests but not telling mod_headers to 'always' set the header?
>
> The optional condition argument determines which internal table of
> responses headers this directive will operate against. Despite the
> name, the default value of onsuccess does not limit an action to
> responses with a 2xx status code. Headers set under this condition are
> still used when, for example, a request is successfully proxied or
> generated by CGI, even when they have generated a failing status code.
>
http://httpd.apache.org/docs/2.4/mod/mod_headers.html#header
(submitted too early)
Location /foo should behave how you expect
--
Eric Covener
covener@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] and partially non-existing directory?
Posted by Eric Covener <co...@gmail.com>.
On Mon, Mar 20, 2017 at 12:30 PM, DUVERGIER Claude
<ht...@claude.duvergier.fr> wrote:
> <Location "/foo">
>
> Header set X-Foo "true"
>
> </Location>
Are you getting mixed up by looking at the headers for unsuccessful
requests but not telling mod_headers to 'always' set the header?
The optional condition argument determines which internal table of
responses headers this directive will operate against. Despite the
name, the default value of onsuccess does not limit an action to
responses with a 2xx status code. Headers set under this condition are
still used when, for example, a request is successfully proxied or
generated by CGI, even when they have generated a failing status code.
--
Eric Covener
covener@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org