treating a subdirectory like a web root directory in xampp

5,274

To get your browser to look for http://foobar on your local machine you'll have to add this line to your host file

127.0.0.1 foobar

Then add a virtual host in your Apache http.conf file,

<VirtualHost *:80>
    DocumentRoot path/to/foobar
    ServerName foobar
</VirtualHost>

You may also have to add another virtual host

<VirtualHost *:80>
    DocumentRoot path/to
    ServerName localhost
ServerAlias 127.0.0.*
</VirtualHost>
Share:
5,274
Evil E
Author by

Evil E

Updated on September 18, 2022

Comments

  • Evil E
    Evil E over 1 year

    I am running Xampp on a Windows 7 machine. I have a website that is running off a directory in my web root. I access the website by going to http://localhost/foobar.

    I would like to set it up so that I can point my local browser to say, http://foobar, and have it treat the foobar directory like the web root directory.

    Is that a matter of changing the hosts file or configuration on apache?

  • Evil E
    Evil E over 11 years
    Thanks, Musa, that worked great! The ServerAlias part was not necessary.
  • Evil E
    Evil E over 11 years
    Some additional info, with xampp the http.conf included the file httpd-vhosts.conf, which is where I made my changes. I also had to uncomment the line NameVirtualHost *:80 to get it to work.
  • Talon
    Talon almost 11 years
    I get: Access forbidden! You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
  • Markus Bruckner
    Markus Bruckner about 10 years
    @Talon Make sure Apache (or whatever server you are using) has access to the directory. For example, storing the data in your user directory C:\users\... might be problematic.