Forum Moderators: mack
I have read that Apache will not send the 'last modified' header for SSI pages, which may mean that browsers won't cache them.
According to various guides, I need to force the headers with a few different commands. The ones that seem relevant for me are:
ExpiresActive On
ExpiresDefault "access plus 1 month"
I've put this in an htaccess file in the appropriate sub directory that I want affected, along with the root htaccess info, i.e. hotlinking, ect.
I'm getting a 500 error with this new file. What am I doing wrong?
Also, I'd like to confirm a couple of things:
1) Htaccess works in top down fashion, i.e., an htaccess file in a sub directory will affect that directory and ALL of its' subdirectories, correct?
2) Subdirectory htaccess files completely replace ones that are lower on the tree, iow, if I leave the subdirectory htaccess file blank, then that directory and all subdirectories would function as if there wasn't one, even if I have one in the root directory. Right?
If this is correct, then if I am wanting to add an item to the root htaccess info to affect one particular directory, then I would need to copy the root htaccess, add the extra item to it, and save the new file to the appropriate directory, correct?
3) The Expires directives affect subdirectories in addittion to the immediate directory, just as all other htaccess commands do, correct?
4) Are there any exceptions to the htaccess override system, i.e., a situation where a root directory htaccess file will override a subdirectory htaccess file?
I'd also appreciate any links to *really good* htaccess and SSI guides. Thanks.
The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.
Welcome to WebmasterWorld [webmasterworld.com]!
1) Yes.
2a) No, because this conflicts with #1. Subdirectories with no .htaccess will be affected by any .htaccess above them in the directory structure.
2b) No, you would only need to add directives in the local .htaccess pertaining to the resources (files) that were unique to that locale. Alternatively, you could handle everything at the root directory level .htaccess by specifying a full path to resources several subdirectories down.
3) You can wrap Expires directives in <files> containers to specify which files they apply to (See Apache core modules).
4) No, not if the resources named in each .htaccess are the same. The .htaccess files are processed sequentially as the server traverses the directory path to the requested resource. In cases of conflict, the .htaccess file closest to the requested resource wins.
I think one point that is sticky is this: Apache won't serve Last-Modified or Expires headers on files which SSI-include other files. This is because determining whether the container file or the SSI-included file(s) should control is ambiguous and therefore beyond what the server can do without some hint from the site administrator.
You can force Apache to unconditionally return the Last-Modified date of the container file by using the XBitHack Full directive, and setting the required file permissions.
Here's an excerpt from one of my sites showing a working cache-control set-up:
# Set up Cache Control headers
ExpiresActive On
# Default - Set http header to expire everything 1 week from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "must-revalidate"
# Apply a customized Cache-Control header to frequently-updated files
<FilesMatch "^(bulog¦test)\.html$">
ExpiresDefault A1
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
<FilesMatch "^index\.htm">
ExpiresDefault A7200
</FilesMatch>
<FilesMatch "^robots\.txt$">
ExpiresDefault A7200
</FilesMatch>
A few links for useful stuff:
[httpd.apache.org...]
[mnot.net...]
[ircache.net...]
HTH,
Jim
One more question for now:
When having 2 htaccess files, an Option directive in a subdirectory htaccess will override Option directives in higher directories, including those in the server configuration file, from what I've read so far.
So, why is it that my root htaccess file can have the 'Option -Indexes' directive, but SSI files still function for me? I know that my host has SSI enabled by default, I just don't understand why my 'Option -Indexes' directive hasn't disabled it, if it's supposed to override prior commands. I _should_ have to have 'Options -Indexes +Includes', if the logic holds.
Here's the example I pulled from [httpd.apache.org...]
"Example:
In the directory /www/htdocs/example1 we have a .htaccess file containing the following:
Options +ExecCGI
(Note: you must have "AllowOverride Options" in effect to permit the use of the "Options" directive in .htaccess files.)
In the directory /www/htdocs/example1/example2 we have a .htaccess file containing:
Options Includes
Because of this second .htaccess file, in the directory /www/htdocs/example1/example2, CGI execution is not permitted, as only Options Includes is in effect, which completely overrides any earlier setting that may have been in place."
I think I see the point of obscurity here...
> my host has SSI enabled by default, I just don't understand why my 'Option -Indexes' directive hasn't disabled it.
First, because -Indexes doesn't affect SSI, and second, because Options -ExecCGI is not the same as Options ExecCGI.
Using the "+" and "-" affects only the named feature. Specifying features without "+" and "-" disables any feature not present in the list. So, "+" and "-" allow you to add or subtract from the list of currently-enabled features, without changing those not mentioned.
HTH,
Jim