2
votes

I want to restrict direct access to a specific directory (and all the files inside) on my local server. The directory is: C:/Server/www/project/html/

I've tried the following code (.htaccess is placed in www directory - /project/html/ doesn't work too):

<Directory "C:/Server/www/project/html/">
    AllowOverride all
        Order Deny,Allow
    Deny from all
</Directory>

However, it causes 500 Internal Server Error and I can't understand why.


Apache error log:

[Fri Aug 05 16:06:01 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:06:01 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:06:01 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:06:01 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:06:01 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:06:02 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:54:12 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
[Fri Aug 05 16:54:12 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here
[Fri Aug 05 17:05:06 2011] [alert] [client 127.0.0.1] C:/Server/www/.htaccess: <Directory not allowed here, referer: http://localhost/project/index.php?id=8
2
If you cannot place it into server config/virtual host, then get rid of the <Directory> and place it in .htaccess file directly (.htaccess in "C:/Server/www/project/html/").LazyOne

2 Answers

10
votes

Check Apache error log for exact error description.

In any case -- the reason for this error is simple: <Directory> directive CANNOT be placed in .htaccess file -- only server config or virtual host.

http://httpd.apache.org/docs/current/mod/core.html#directory

0
votes

for me it required enable headers module to apache