Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Require directive to limit file access in apache 2.4

I have a directory structure like the following for a website on Ubuntu 14.04, running apache 2.4.7:

/websites/mywebsite/index.htm
/websites/mywebsite/private.htm
/websites/myqwbsite/folder/privatefile.ext
/websites/mywebsite/folder/subfolder/publicfile.ext

In the Apache config for the site, I have

<Directory /websites/mywebsite/>
   AllowOverride Limit
   Require all granted
</Directory>

I want to use .htaccess files in the site folder such that the private.htm and privatefile.ext files are Require all denied but everything else is granted.

I tried the following two .htaccess files:

/websites/mywebsite/.htaccess:

<FilesMatch (private.*.htm)$>
   Require all denied
</FilesMatch>

/websites/mywebsite/folder/.htaccess:

Require all denied

/websites/mywebsite/folder/subfolder/.htaccess:

Require all granted

However, apache gives a 500 - "Require not allowed here" for /websites/mywebsite/.htaccess

How can I make what I want happen with apache 2.4-compatible configuration (ie I do not want to load mod_access_compat and use the old style config)?

like image 212
dodexahedron Avatar asked Jul 26 '14 01:07

dodexahedron


People also ask

What is the purpose of AllowOverride directive?

The AllowOverride directive sets whether any Options can be overridden by the declarations in an . htaccess file. By default, both the root directory and the DocumentRoot are set to allow no . htaccess overrides.

What is directive in Apache configuration?

Apache directives are a set of rules which define how your server should run, the number of clients that can access your server, etc. you can configure them by using the apache2. conf or httpd. conf files.

What directive is used in Apache to load a module?

9: LoadModule LoadModule is the directive used to inform the Apache server of a module to be loaded. Tons of modules are included in a default Apache installation — and more can be found.


1 Answers

In the apache config for the site, you have to extend AllowOverride properties. Add: FileInfo and AuthConfig. Or set "AllowOverride All"

I had same problem, fixed with this config :

<Directory /websites/mywebsite/>
   Options +FollowSymLinks +SymLinksIfOwnerMatch
   AllowOverride FileInfo AuthConfig
</Directory>
like image 163
jtef Avatar answered Nov 01 '22 15:11

jtef