views:

45

answers:

2

Hi all,

I have this regex that allow all php files :

^.*\.([Pp][Hh][Pp])

how can I exclude a specific file, for example test.php ?

Thanks for your answer, Best regards

[edit] I omit to say that it is a reg from a htaccess file, the /i doesn't seems to work, and the ? neither. [Edit2] the purpose is to grant access to authenticated users, except for one file that has to be allowed for everyone. So I've done :

<Files ~ "^.*\.([Pp][Hh][Pp])$">
AuthUserFile /directory/.htpasswd
AuthGroupFile /dev/null
AuthName "Please log in ..."
AuthType Basic
require valid-user
</Files>

So, all php files require valid user. I would like to add an exception for a specific file, says test.php

+4  A: 

You could use a negative lookahead:

^(?!test\.php$).*\.([Pp][Hh][Pp])$

It might be better to use a case-insensitive regular expression instead of writing things like [Pp] for each letter.

"/^(?!test\.php$).*\.php$/i"
Mark Byers
thanks for your answer, but i omit to say that it is a reg from a htaccess file, the /i doesn't seems to work, and the ? neither. Is there another way to write this ?
Tim
A: 

Wouldn't it be better to implement non-regex check in this case?

UPD:

just add second directive for the excluded file like this:

<Files "test.php">
Satisfy Any
Allow from all
</Files>

This will grant test.php to be available for all users.

FractalizeR
maybe, how would you do that ?
Tim
You need to add second <Files> directive like this: <Files "test.php">\n Satisfy Any\n Allow from all\n </Files>\nBy this test.php will be available for all.
FractalizeR