Im not that familiar with Apache.
<Location>
, I am able to redirect users to a sign-on page, forcing them to authenticate and have proper privileges before accessing the URL.<Directory>
, it is supposed to allow me to control access to specified folders and directories, right?Question:
How does <Directory>
behave similarly and differently from <Location>
?
<Location /web>
: www.mysite.com/web and www.mysite.com/web/foo will be controlled.<Directory /webforms>
: how will www.mysite.com/web look like if some of the scripts are from that folder?<Directory /pictures>
: how will www.mysite.com/web look like if some of the picture are from that folder?The usage is straightforward - you would use Location if you need to fine tune access rights by an URL, and you would use Directory if you need to control access rights to a directory (and its subdirectories) in the filesystem.
Directives in the configuration files may apply to the entire server, or they may be restricted to apply only to particular directories, files, hosts, or URLs. This document describes how to use configuration section containers or . htaccess files to change the scope of other configuration directives.
Therefore, the UserDir directive specifies a directory underneath the user's home directory where web files are located.
The DocumentRoot directive specifies where in your filesystem you should place these files. This directive is either set globally, or per virtual host.
The Apache HTTP server documentation has a section called What to use When which, I think, directly, answer your question :
Choosing between filesystem containers and webspace containers is actually quite easy. When applying directives to objects that reside in the filesystem always use
<Directory>
or<Files>
. When applying directives to objects that do not reside in the filesystem (such as a webpage generated from a database), use<Location>
.
The important part is the following :
It is important to never use
<Location>
when trying to restrict access to objects in the filesystem. This is because many different webspace locations (URLs) could map to the same filesystem location, allowing your restrictions to be circumvented.
Read on for more information...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With