Web Servers General Talk - Regular expressions in <FilesMatch> directive

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers General Talk > July 2004 > Regular expressions in <FilesMatch> directive





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Regular expressions in <FilesMatch> directive
Joe

2004-07-15, 6:00 pm

Using Apache 2.0 I'm attempting to require user validation for access
to files in a directory "except" those with a ".txt" extension. I've
tried all kinds of "regular expressions" in the "FilesMatch" directive
in the .htaccess file, some with limited success.

I thought <FilesMatch "!(\.txt$)"> would yield a match for all files
that do not end with ".txt". This does not work; however, if I use
<FilesMatch "\.txt$"> I can match all files that do end with ".txt".

What I have found is that whenever I use the "!" in a regular
expression I do not get the results I'm expecting. Is the use of
regular expressions in <Files> and/or <FilesMatch> limited such that
"!" is not going to work?

I've tried getting this to work using Apache 1.3 and Apache 2.0 on
both Win32 and OpenVMS systems.

I'd appreciate some direction on this one. My .conf file and
..htaccess files follow.

Thank you.

My joe.conf file includes...

<Directory "C:/Apache/test" >
Options Indexes Includes ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Alias /test "C:/Apache/test"

<Directory /test/userdir >
AllowOverride None
Options Indexes MultiViews
</Directory>

#
# Require username/password
# (defined in C:\Apache\test\userdir1\.htaccess)
#
<Directory /test/userdir1 >
Options Indexes Includes MultiViews
AllowOverride AuthConfig
</Directory>


My C:\Apache\test\userdir1\.htaccess file contains...

AuthType Basic
AuthName "The Big Authority"
AuthUserFile "C:/Apache/joespasswords.txt"
<FilesMatch "!(\.txt$)">
require valid-user
</FilesMatch>
Klaus Johannes Rusch

2004-07-16, 5:56 pm

Joe wrote:

> Using Apache 2.0 I'm attempting to require user validation for access
> to files in a directory "except" those with a ".txt" extension. I've
> tried all kinds of "regular expressions" in the "FilesMatch" directive
> in the .htaccess file, some with limited success.
>
> I thought <FilesMatch "!(\.txt$)"> would yield a match for all files
> that do not end with ".txt". This does not work; however, if I use
> <FilesMatch "\.txt$"> I can match all files that do end with ".txt".
>
> What I have found is that whenever I use the "!" in a regular
> expression I do not get the results I'm expecting. Is the use of
> regular expressions in <Files> and/or <FilesMatch> limited such that
> "!" is not going to work?


Negation of the whole pattern is not supported by regular expressions,
some applications allow a leading exclamation mark to invert the result
of a regular expression pattern match.

An alternate approach is to apply rules to all files, then override with
the default for the files you want to exclude.

--
Klaus Johannes Rusch
KlausRusch@atmedia.net
http://www.atmedia.net/KlausRusch/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com