How to Add Virtual Directory Alias on Apache Xampp

Do you want to create some alias or you can call it virtual directory on Apache Xampp? I’m using Windows Xampp as an example here. If you’re using Linux, you just need to adjust the path.

Why do you need an alias or virtual directory?

Supposed you have installed Xampp on some directories, like:

C:\Program Files\xampp\

And the default document root would be in:

C:\Program Files\xampp\htdocs

But, my source code are all outside that htdocs directory, example:

D:\sources

I know that the most easiest way is to copy and paste all of them into htdocs directory. But that’s not what I want to be.

So, I decided to add an alias or virtual directory in my Apache web server.

How do I do that?

  1. Open the httpd.conf file, it’s located in this directory:
    C:\Program Files\xampp\apache\conf
  2. Add these lines on the bottom of the httpd.conf file:
    Alias /sources "D:/sources"
    
    <Directory "D:/sources">
    	Options Indexes FollowSymLinks Includes ExecCGI
    	AllowOverride All
    	Order allow,deny
    	Allow from all
    </Directory>

    Pay attention to the bold parts. In Windows, normally we’re using “Backslash” or \, but here we must use “Forward Slash” or /

  3. Restart your Xampp
  4. Open your web browser and test it by go to http://localhost/sources

Hope it helps. If you found some error while doing it, just leave a comment here, maybe I can help you out.

— Updated: February 24, 2013 —

If you’re getting error 403 Forbidden like these:

Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403

Maybe you can add this line inside the <Directory></Directory> block:

Require all granted

So, the final code will be like this:

Alias /sources "D:/sources"

<Directory "D:/sources">
	Options Indexes FollowSymLinks Includes ExecCGI
	AllowOverride All
	Order allow,deny
	Allow from all
	Require all granted
</Directory>
Comments