Forum Moderators: phranque

Message Too Old, No Replies

Files or FilesMatch excluding subdirectories?

         

Umbra

8:33 pm on Jul 6, 2008 (gmt 0)

10+ Year Member



I apologize if this has been discussed before, but I couldn't find the relevant thread(s)

If one of these directives are in .htaccess...

<Files test>
ForceType application/x-httpd-cgi
</Files>

..OR..

<FilesMatch "test">
ForceType application/x-httpd-cgi
</FilesMatch>

Then this seems to affect example.com/test AND example.com/dir/test

Whereas I'm looking to apply it to ONLY one specific file, excluding subdirectories. What did I miss?

jdMorgan

3:48 pm on Jul 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The <FilesMatch> directive, as implied by its name, looks only at the filename, and not at the filepath info.

You could put additional .htaccess files in the subdirectories, using RemoveType to override the 'global' file setting in higher-level .htaccess files. A better approach would be to use a consistent filename-handling plan.

Remember that filenames and URL-paths need not resemble each other; You can use mod_rewrite to 'map' any URL to any filepath/filename/filetype. Therefore, having separate URL-based directives and filename-based directives is quite useful.

For example, if you use extensionless URLs, then filename-based directives are required to enable you to set MIME-types based on the filetype, not the URL. Since the URLs have no "file extensions," this would be impossible without filename-based directives.

See Apache mod_mime for more info on RemoveType

Jim