Forum Moderators: phranque

Message Too Old, No Replies

FilesMatch stopped working

         

ahmedtheking

6:25 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any idea why this has just stopped working?

<FilesMatch "\.(inc¦cfg¦pwd¦fcn¦rsrc¦tmp¦js¦css¦cron¦bck¦bld¦xml¦mnu)\.php$">
Order Deny,Allow
Deny from All
</FilesMatch>

jdMorgan

6:46 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I had to guess, I'd say the closing parenthese is not in the right place, unless you have files like "something.css.php" -- All files matching that pattern must end with ".php" as written.

Jim

ahmedtheking

10:28 pm on Jan 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's right, all my files are like inc.php, etc...

jdMorgan

1:22 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, it should work, on the face of it.

Have you made other recent changes?

Is there another "Order" statement in your config? (Only the last one is applied in .htaccess in some cases)

FilesMatch means "files" so it does not care what directory the file is in -- this directory, or any directory below it, or what URL was used to reach it.

Deny,Allow means that any Allow in an equally- or more-widely-scoped container can override the Deny. So be careful about both the Order [httpd.apache.org] that you select and the scoping of the Denys and Allows. If that's too complex, or if you don't need the scoping behaviour, you can always just use a RewriteRule with an [F] flag to unconditionally deny access to the URL-paths corresponding to those files:


RewriteRule \.(inc¦cfg¦pwd¦fcn¦rsrc¦tmp¦js¦css¦cron¦bck¦bld¦xml¦mnu)\.php$ - [F]

Jim

ahmedtheking

9:36 am on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This really really strange. There aren't any other conflicting rules and it's started working again, I think because I restarted Apache! Hmmm!

ahmedtheking

12:20 pm on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now it's stopped working! This is really really weird! Could it be the server?

jdMorgan

2:44 pm on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Question: Are you flushing your browser cache (IE Temporary Internet Files) before "testing" this by viewing/including/downloading these resources?

If not, your browser will happily show you previously-cached copies, unless the files' cache-controls prohibit this (check the server response headers).

You can verify that this is happening by looking at the raw server access logs: Either you won't see your own requests for these files at all, or you'll see a 304-Not Modified response or a 200-OK response with a transfer byte count of zero.

Jim

ahmedtheking

2:48 pm on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No browser cache, + I'm on Mac so FireFox all the way. It turned out to be something really stupid... It was htaccess's encoding! You see, for some strange reason, rewrite rules and all that worked when it's encoded as Mac (because the server is Mac OS X) but when I encoded it as Unix, then filesmatch started working. Strange.

jdMorgan

9:32 pm on Jan 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm glad you figured it out -- I would have never thought to ask about platform-related encoding issues!

Jim

ahmedtheking

12:47 am on Jan 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lol, it's always something like that!