View Full Version : htaccess deny all, allow php's readfile()

04-20-2009, 06:50 PM
Hey all,

I'm trying to create a htaccess file that will do the following: it has to deny access to all .split files (located in subfolders). In addition it will allow the 'dl.php' file to read the .split files (php's readfile() function (or fopen() or ...)).

The folder structure:

| -- .htaccess
| -- dl.php
| -- example1
| | -- 0.split
| | -- 1.split
| ` -- 2.split
| -- example2
| -- 0.split
| -- 1.split
` -- 2.split

At this site (askapache.com) (http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html) I found this snippet:

Deny access to anything in a subfolder except php fopen
This can be very handy if you want to serve media files or special downloads but only through a php proxy script.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]
RewriteRule .* - [F,L]
but I'm new to htaccess (and regexp :p) so I've no clue how to edit the script so It'll work (I tried).

Thanks in advance.

I forgot to tell, anyone should be able to access the dl.php file...!

04-26-2009, 08:58 PM

<FilesMatch ".\.split$">
Dent from all

04-27-2009, 04:59 PM

Suppose it's 'deny' instead of 'dent'? At any rate, it worked! Perfect. And so simple... :p