Reputation: 133
Using Ubuntu with apache2:
In my sites-enabled
config I have an Alias
command like so:
Alias "/someDir" "/webSiteDir"
It works great.
So, the absolute path of /someDir
is actually a "virtual directory" which effectively exists at /var/www/html/someDir
. Whereas /webSiteDir
actually exists at the root of the Ubuntu box's file system.
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 Alias
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 var/www/html
within the very same config.
Should I be using a different command other than Alias
for when both directories are under the same document root?
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"
/anotherDir
is treated as a "virtual directory" under /var/www/html/
but the second part which is /var/www/html/thisDir
is treated as an absolute path with regards to the Ubuntu file system.
Ok fine, maybe that is just the syntax of the Alias
command, in that the first entry is always relative and the second entry is always absolute.
Well what about the <Directory>
attribute?
I have one entry:
<Directory "/">
which seems to refer to the document root of /var/www/html/
- a relative path.
And I also have:
<Directory "/thisDir">
which seems to refer to /var/www/html/thisDir
- another relative path
Whereas I have another:
<Directory "/webSiteDir">
which seems to refer to an absolute path in the file system of /webSiteDir
.
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?
Upvotes: 1
Views: 1619
Reputation: 2890
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.
Upvotes: 1