Setting a URL to go to Localhost folder on XAMPP server

15,854

So far I've just tried the HOSTS file, but that didn't work as it doesn't allow directories.

It works fine really. But you need to realize that "domain to IP" translation and "domain to path" are two entirely separate tasks, done at different levels, by different software.

The first translation happens before reaching the web server; it just tells you where the server is. (Both DNS and /etc/hosts are just "phone books"; they tell you who to talk with, but they don't decide what you'll be saying.) So using 127.0.0.1 arch.elm in /etc/hosts is good enough, because the second decision (domain to path) is done by the web server.

In Apache httpd (which XAMPP uses), you can configure this by adding a new "VirtualHost" section corresponding to your new domain name, and by specifying the DocumentRoot that you want. For example:

<VirtualHost *:80>
    ServerName arch.elm
    DocumentRoot c:/xampp/htdocs/archelm
</VirtualHost>

When the web browser says "I'm expecting to reach Host: arch.elm", Apache will find the apropriate VirtualHost section. (If it doesn't find any, it'll use the first one it has.)

Share:
15,854

Related videos on Youtube

owenvoke
Author by

owenvoke

Updated on September 18, 2022

Comments

  • owenvoke
    owenvoke almost 2 years

    I have a local XAMPP server. How can I make the domain arch.elm redirect to the localhost/archelm location? This only needs to happen on the server PC, as that's the only PC I use.

    I am using Windows 10 (if that helps).

    So far I've just tried the HOSTS file, but that didn't work as it doesn't allow directories.

  • Carl Angelo Nievarez
    Carl Angelo Nievarez about 6 years
    Nice! Work's great! :) :)