Apache, Directory Aliases and Virtual Directories

I realized I misconfigured Apache the other day. Apache wasn't serving files from my virtual directory, rather from the root folder named the same. After looking at my Apache configuration, I noted I was missing a leading slash in my Alias directive. Sort of hard to spot, so I hope this helps someone else.

This is the misconfigured version: ( Bad )

view plain print about
1Alias /portal "C:\httpd\Apache2\htdocs\Portal\www"
2<Directory "C:/httpd/Apache2/htdocs/Portal/www">
3 Options Indexes FollowSymLinks MultiViews ExecCGI
4 AllowOverride All
5 Order allow,deny
6 Allow from all
7</Directory>

This is the one that works: ( Good )

view plain print about
1Alias /portal/ "C:/httpd/Apache2/htdocs/Portal/www/"
2<Directory "C:/httpd/Apache2/htdocs/Portal/www">
3 Options Indexes FollowSymLinks MultiViews ExecCGI
4 AllowOverride All
5 Order allow,deny
6 Allow from all
7</Directory>

Note: The slashes have been changed from \ ( Windows Style ) to / ( Unix Style ). For some reason this mattered.....

100975 Views Print Print Comments (4) Apache

There are no comments for this entry.

Add Comment Subscribe to Comments

8/21/08 1:32 AM # Posted By Drale

On my Apache 2.2 install on Windows I did it like this.

Alias /myfolder "C:/path/to/myfolder/"
<Directory "C:/path/to/myfolder/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

So when I type http://www.mysite.com/myfolder without slash in browser it still loads. If I had "Alias /myfolder/" I am required to type the trailing slash in the browser or I get an error "The requested URL /myfolder was not found on this server.".


10/11/10 3:29 PM # Posted By ptzacs

Thanks that helped save me a lot of head scratching.


12/21/11 6:56 AM # Posted By Ian

Guys, Check this out:
http://httpd.apache.org/docs/2.0/mod/mod_alias.htm...
It seems that it you place a / at the end of the target path, you need it at the end of the alias too (and vice-versa) makes sense really. Oh and back-slashes are escapes whereas forwards are for paths. I have Bill Gates' number somewhere, now where did I put it....


9/17/15 10:19 PM # Posted By PETE

WOAH!, man.

This did the trick for me.

It is amazing how, in the Apache Documentation: not much is said about including the drive the folder is on, in the file path (unless I missed something).

Your example just worked, first time round. Unlike, the other documentation (not to mention other blogs), which tend to be quite vague, in their help articles.

Thanks again.


Add Comment Subscribe to Comments