You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2018/05/30 13:47:52 UTC

[Bug 62418] New: Be able to apply directives to a single file

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

            Bug ID: 62418
           Summary: Be able to apply directives to a single file
           Product: Apache httpd-2
           Version: 2.5-HEAD
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Core
          Assignee: bugs@httpd.apache.org
          Reporter: hontvari@flyordie.com
  Target Milestone: ---

I had to apply an ExpiresDefault directive to a single file. This is
surprisingly difficult and differ between Apache versions. I have come up with
two solutions, see
https://serverfault.com/questions/914295/how-to-apply-an-expiresdefault-directive-to-a-single-file-excluding-similar-fil/914443#914443

First solution:

<If "%{REQUEST_FILENAME} == '%{DOCUMENT_ROOT}/index.html'">
    ExpiresDefault "access plus 1 hours"
</If>

This works in a .htaccess file, but it is awkward, because the right side of
the condition must include the path to the .htaccess file. The directory should
be implicit from the location of the .htaccess. This example is the best case,
in a  wronger case the expression would be something linke
%{DOCUMENT_ROOT}/alfa/beta/index.html, if the .htaccess file is in alfa/beta.

The second solution:
<DirectoryMatch "^/srv/www-example-com/[^/]*$">
    <Files "index.html">
        ExpiresDefault "access plus 1 hours"
    </Files>
</DirectoryMatch>

This does not work in .htaccess. It is also very verbose. 

It also shows a bug in this Apache HTTPD version (2.4.18): DirectoryMatch
matches the full path of URL, including the last file name part. This is why
the closing /[^/]* expression is required before the $ sign. Otherwise it would
not match the www.example.com/index.html URL.

What I would expect is something like:

<File file1 file2 file3>
    ExpiresDefault "access plus 1 hours"
</File>

which does not match files in subdirectories, only the current directory in
.htaccess. it works for multiple files, and it is short. If used in a virtual
host context, then file1 must include the absolute path.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org