Forum Moderators: phranque

Message Too Old, No Replies

DirectoryMatch Only for Current Directory (No Subdirectories)

         

closedhomes

5:27 pm on Oct 1, 2008 (gmt 0)

10+ Year Member



Hello:

I am using the AddHandler directive in a .htaccess file to tell PHP to parse .html files in the current directory. However, I don't want any files in any subdirectories to be parsed; only the current directory.

I would assume that <Directory> or <DirectoryMatch> can do the trick, but how to use the right regex to only parse the current directory is the problem.

Looks something like this:

<DirectoryMatch "regex for current directory only goes here">
AddHandler x-httpd-php5 .html
</DirectoryMatch>

Any advise on how to get this to work?

PS: Can <Directory> or <DirectoryMatch> be used in an .htaccess file? If not, how to get it to work?

Thanks.

--
Ed

jdMorgan

5:57 pm on Oct 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As documented, DirectoryMatch is not available in the .htaccess context, because .htaccess isn't parsed until too late in the API processing to be applied there -- The server has already resolved the directory in order to find the .htaccess file.

In .htaccess, you're limited to using <Files> or <FilesMatch>, neither of which care about the directory path, and only see the filename. So they're of little use.

I'd suggest you look into using XBitHack instead (see Apache mod_includes). Or you could rename the files to .php, and then use mod_rewrite to re-connect the existing .html URLs to the newly-renamed files using an internal rewrite.

Jim