0

I have a domain which points to my IP address, now I want to do the following: if I access the server locally (localhost / 127.0.0.1) I want it to server the pages from default DocumentRoot. If I access the server using the domain name, it servers files from other directory.

I edited httpd.conf adding following lines:

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot "C:/Xampp/htdocs/mydomain"
   ServerName mydomain.com
</VirtualHost>

unfortunately, it doesn't work as expected - it serves files from "C:/Xampp/htdocs/mydomain" even if I access the server via localhost.

How do I fix it?

1 Answer 1

2

Here is what you want:

http://httpd.apache.org/docs/1.3/vhosts/name-based.html

Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a container and list it first in the configuration file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .