Daniel Daniel - 1 year ago 135
Apache Configuration Question

in apache config, how should I use the Alias module for a directory in the document root?


Using Ubuntu with apache2:

In my
config I have an
command like so:

Alias "/someDir" "/webSiteDir"

It works great.

So, the absolute path of
is actually a "virtual directory" which effectively exists at
. Whereas
actually exists at the root of the Ubuntu box's file system.

Question 1

How would I créate an Alias from one directory in the document root to another directory also in the document root? The manual for Apache specifically says that
should be used for redirecting to directories outside the document root. So what should I use if both the "virtual directory" and the actual directory are inside the document root?

Right now, I have it working with the following line:

Alias "/anotherDir" "/var/www/html/thisDir"

That seems quite clunky when the document root is explicitly defined just a few lines up as
within the very same config.

Should I be using a different command other than
for when both directories are under the same document root?

Question 2

How does the apache config even correctly determine the absolute path of different entries?

For example, in the above line:
Alias "/anotherDir" "/var/www/html/thisDir"
is treated as a "virtual directory" under
but the second part which is
is treated as an absolute path with regards to the Ubuntu file system.

Ok fine, maybe that is just the syntax of the
command, in that the first entry is always relative and the second entry is always absolute.

Well what about the

I have one entry:

<Directory "/">

which seems to refer to the document root of
- a relative path.

And I also have:

<Directory "/thisDir">

which seems to refer to
- another relative path

Whereas I have another:

<Directory "/webSiteDir">

which seems to refer to an absolute path in the file system of

So, is my config file just messed up, or does apache somehow know when something is a relative path to the document root, or an absolute path from the system root?

Answer Source

Alias does not care much about your documentroot in a sense. That is, just define Alias inside your VirtualHost, first argument is a new virtual path and second is always a filesystem path, can be or it can not be inside the documentroot, Alias does not care or differentiate about it.

So, to question 1.

Always use alias to define virtualpaths, irrespectively where the filesystem is, just use it when you need it.

To question 2.

You have a BIG misunderstanding, Directory ALWAYS specifies a full path in your OS, that is <Directory "/">is / in your OS Filesystem and the same with the rest of your "Directory" examples.

If you wanted to affect a path created with Alias, you would use "Location" or Directory with the full path, and that one is really relative to documentroot.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download