I created a virtual host for my project "phpiggy" using XAMPP for Apache and PHP. Here's the configuration I added to httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/CMPD/phpiggy/public"
ServerName phpiggy.local
</VirtualHost>
I also added this line to the hosts file:
127.0.0.1 phpiggy.local
After restarting Apache, typing "phpiggy.local" in the browser URL works correctly and points to the intended directory.
However, when I type "localhost" in the browser URL, it doesn't show the default files/folders under htdocs as expected.
Is this normal behavior? After creating a virtual host, can't I use localhost anymore to access other files in htdocs, only the directory specified in the virtual host?
While writing this, I tried reenabling the usual localhost by commenting the lines I added in httpd-vhosts.conf and the hosts file and then I uncomment and then tried again and did that a few times. Now, even after I wrote those codes in the httpd-vhosts.conf and hosts, when I typed "phpiggy.local" in the browser URL, now it says
ERROR
The requested URL could not be retrieved
Edit: Now, I realized when I type "localhost", it is routing to the files/folder under C:/xampp/htdocs/CMPD/phpiggy/public and when I type "phpiggy.local" I get an error as I said above.
I hope to be able to be able to access the files/folders under htdocs by typing "localhost" in the URL and if possible and not a very hassle to do, then I would like to access to the files/folder under C:/xampp/htdocs/CMPD/phpiggy/public when type "phpiggy.local"
Okay, I think I found a solution. Instead of just only restarting the Apache server by turning off and on again after making changes in the configuration settings, also restart your laptop. Because for me, only by also restarting the laptop after making changes affects the configuration changes. When I don't restart my laptop and make changes, it gives me the error I described in the question.