Martyn
Martyn

Reputation: 6403

Grant access to only one directory with .htaccess

I want to only provide public access to a single directory (/dist). I have an .htaccess file with the following:

Order deny,allow
Deny from all

<Directory /dist>
    Order Allow,Deny
    Allow from all
</Directory>

I'm trying to first deny access to all, then overwirte that directive with a allow rule for the /dist directory. However, when I try to access any file through the browser, I get the following:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

What am I doing wrong?

Upvotes: 5

Views: 2145

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

As @Anubhava said, Directory dirctive is not allowed in htaccess contex ,this directive is available for use only in Directory context. You can use a RewriteRule to deny access to all except /dist directory :

RewriteEngine on

RewriteRule !dist - [F]

This will forbid all incomming requests except a request for /dist.

Upvotes: 6

Related Questions