Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache - Location vs Directory Directives

Tags:

apache

Im not that familiar with Apache.

  • When using <Location>, I am able to redirect users to a sign-on page, forcing them to authenticate and have proper privileges before accessing the URL.
  • When using <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>?

  • With <Location /web>: www.mysite.com/web and www.mysite.com/web/foo will be controlled.
  • With <Directory /webforms>: how will www.mysite.com/web look like if some of the scripts are from that folder?
  • With <Directory /pictures>: how will www.mysite.com/web look like if some of the picture are from that folder?
  • What about a situation where you have both types of directives active and affecting a single page? What kinds of things should I expect or watch out for?
like image 309
agent provocateur Avatar asked Jul 13 '15 23:07

agent provocateur


People also ask

What is the main difference between location and directory sections?

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.

What is Apache directory directive for?

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.

Which Apache directive specifies the location of the HTTP documents?

Therefore, the UserDir directive specifies a directory underneath the user's home directory where web files are located.

What is the Apache configuration directive that specifies the folder location from where a Virtualhost's static files are served from?

The DocumentRoot directive specifies where in your filesystem you should place these files. This directive is either set globally, or per virtual host.


1 Answers

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...

like image 59
Ortomala Lokni Avatar answered Sep 27 '22 23:09

Ortomala Lokni