Welcome to WebmasterWorld Guest from 54.242.193.41

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Apache <Files> Directive

How to specify a subdir?

     
8:54 am on Sep 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Hi all,

I can't seem to reach the apache docs on their site so just a quckie...

If I have a file like this:
/path/to/file

How do I specify it in my .htaccess at root level? I have tried:
<Files /path/to/file> and <Files path/tofile> but neither work...?

Many thanks...

Nick

9:12 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 15, 2003
posts:2412
votes: 5


I'm glad i've got it in a book then ;)

I'm not sure though; the thread title suggests you want to match a directory and your post mentions a file. If it's a file, then this is the way (just a filename):

<Files file.html>
....
</Files>

If it's a file in a specific subdir, you apparently have to make it a regexp or use FilesMatch (preferred) in stead:

<Files ~ "path/to/file.html">
....
</Files>

or:

<FilesMatch "path/to/file.html">
....
</FilesMatch>

No tilde "~" needed in the last one, as it uses regexps by default. Hope one of these will do the trick.

/claus

9:24 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Thanks Claus,

Only trouble is that doing either with

ForceType application/x-httpd-php

Shows the php source code?

whreas

<Files *>

Does not?

Any ideas there?

(it is a specific file without an extention: like 'file')

Nick

9:46 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 15, 2003
posts:2412
votes: 5


Okay, i've never used that one and the big book suggests using <Directory> with it, but <Directory> does not go with .htaccess.

This might do it though:

<Files file> 
ForceType application/x-httpd-php
</Files>

Just the file name, but this will match that filename in all directories. Or:

<FilesMatch path/to> 
ForceType application/x-httpd-php
</FilesMatch>

Just the directory name, perhaps even like this (added "/" and ".*" although the last should not be necessary):

<FilesMatch /path/to.*>

Here's an article i just found that suggests the first way to do it:
[devarticles.com...]

/claus


added:

The asterisk makes sure that all files everywhere ("any sequence of characters") are matched and treated as php, that's why it works (or perhaps not, your gifs also becomes php that way). This makes me think that the problem is that the right file is not matched, so it's a regexp issue. This might do it:

<FilesMatch "^/path/to/filename$">

included ^ to mark start of path and $ to mark the end. Enclosed it all in double quotes, these might not be needed after all.

[edited by: claus at 10:10 am (utc) on Sep. 3, 2003]

10:06 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Thanks Cluas, much experimenting to do! ;)

Nick

10:34 am on Sept 3, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 15, 2003
posts:2412
votes: 5


I've been looking round a little... it's the usual "logic" thing, it's not clearly stated at one place, you have to combine a few facts to get it. The <Files> accept one argument, "filename". Filename, in turn is:

"The name of a file with no accompanying path information as in file.html."

So the regexps will send Apache looking for the path to match within the filename, and as the path is preceding the filename it is not part of it.

So, either you use that rule on all files everywhere with the same name or you use a separate htaccess file in the directory with the right file in it.

/claus