Forum Moderators: phranque
SetEnvIf {banned IP address} blocked SetEnvIf Request_URI "^(/an/allowed\.file|/another/allowed\.file|/AndSoForth\.files)$" allowed <Files *>
order deny,allow
deny from env=blocked
allow from env=allowed
</Files> <Files "forbidden.html">
Order Deny,Allow
Allow from all
</Files>
Then you don't need to think about further environmental variables, because <Files> or <FilesMatch> will set its own rules. And you don't need to change anything because you're lucky enough to have moved up to 2.4 ;) SetEnvIf Remote_Addr ^128\.30\.52 !keep_out # Block bad-bots using lines written by bad_bot.pl script above
SetEnvIf Request_URI "^(/403.*\.html|/robots\.txt)$" allowsome
<Files *>
order deny,allow
deny from env=getout
allow from env=allowsome
</Files>
not2easy said:
...this is the section of .htaccess from that thread:order deny,allow
deny from env=getout
allow from env=allowsome
lucy24 said:
Does Apache 2.4 simply not recognize the * locution?
lucy24 said:
I'm not getting...why the wild-card <Files *> envelope is needed at all...
lucy24 said:
I'm not getting...why the files that get special treatment can't simply be listed in a <Files> envelope of their own, with its own access rules.
<Files "^(/an/allowed\.file|/another/allowed\.file|/AndSoForth\.files)$">
Require [someting]
</Files> I'm using "<Files *>" to block access to everything on the server
each group is processed in the order that they appear in the configuration files.
Nested sections are merged after non-nested sections of the same type.
...
Sections inside <VirtualHost> sections are applied after the corresponding sections outside the virtual host definition. This allows virtual hosts to override the main server configuration.
Later sections override earlier ones, however each module is responsible for interpreting what form this override takes. A later configuration section with directives from a given module might cause a conceptual "merge" of some directives, all directives, or a complete replacement of the modules configuration with the module defaults and directives explicitly listed in the later context.
Using a separate envelope is fine by me. Would the envelope be something along the lines of the following?<Files "^(/an/allowed\.file|/another/allowed\.file|/AndSoForth\.files)$">
Require [ someting ]
</Files>
Directives enclosed in a <Files> section apply to any file with the specified name, regardless of what directory it lies in.
Would I need an "AllowOverride" to override the "blocked" environment?
<Files "robots.txt">
Order Deny,Allow
Allow from all
</Files>
so no malign robot can ever say "But I tried to read robots.txt ::whine:: and they wouldn't let me."
lucy24 said:<Files "robots.txt">
Order Deny,Allow
Allow from all
</Files>
lucy24 said:
If there is a risk of other, no-special-handling files having the same name, you'd need to put the rules inside <Directory> sections for the first part of each path.
<Files *>
<RequireAll>
Require all granted
Require not env blocked
</RequireAll>
</Files>
<Files .htaccess>
Require all denied
</Files>
<FilesMatch "403.php|403oops.htm|403thank.htm|terms.htm|linking.htm|license.htm|trynguess.php|purple.png|logo.gif|mailit.php$">
Require all granted
</FilesMatch> I'm pretty sure that I cannot use this "Order Deny,Allow" syntax
Require all granted
for universal access. Other than that, the naming and arrangement of the <Files> envelopes is the same for, afaik, every Apache version ever. I'm trying to accomplish this all within the .htaccess file.
<FilesMatch "403.php|403oops.htm|403thank.htm|terms.htm|linking.htm|license.htm|trynguess.php|purple.png|logo.gif|mailit.php$">
<FilesMatch "(403|trynguess|mailit)\.php)">
blahblah
<FilesMatch "(403\w+|terms|li(nking|cense))\.htm">
blahblah
<FilesMatch "(purple\.png|logo\.gif)$">
blahblah
but at this point we're into individual coding style. If you really do have a multitude of possible 403 documents, I do strongly recommend a locution like <FilesMatch "403\w*\.(htm|php)">
to cover all possibilities. <FilesMatch "403.php|403oops.htm|403thank.htm|terms.htm|linking.htm|license.htm|trynguess.php|purple.png|logo.gif|mailit.php$">
All those . should be escaped. (This is a good example of a non-lethal error, since the chances are pretty minute that any non-period could occur in this location.)
<FilesMatch "^\.ht">
Order Deny,Allow
Allow from all
</FilesMatch>
in your htaccess, and that would override the config file's bar on people looking at your htaccess and htpasswd files. (Here I've deliberately made up the most ridiculously unlikely scenario ever.)