TheClassyCoder
TheClassyCoder

Reputation: 103

Why URL can't go to other folder directories using XAMPP?

The first time I used XAMPP, I created a folder named E_Shop and ever since I hit localhost or 127.0.0.1 in my URL address bar of my browser, I am directed to this E_Shop folder I created once,

now I have created another folder named PHP_execises in the same location I created E_Shop, in the htdocs folder of XAMPP folder, and I created a PHP file inside PHP_exercises, and here is the problem as you might guess: In the URL bar of the browser, hitting localhost/PHP_exercises pops an URL error, and hitting localhost alone, directs me to the E_Shop folder as default, and not the XAMPP file directories!

I've checked my C:\Windows\System32\drivers\etc\hosts, it has this code inside:

#
#127.0.0.1 localhost
#::1 localhost
::1 localhost

And inside C:\xampp\apache\conf\extra\httpd-vhosts.conf is:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin [email protected]
    ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/E_Shop"
    ServerName bookshop.com
    ErrorLog "logs/bookshop.com-error.log"
    CustomLog "logs/bookshop.com-access.log" common
</VirtualHost>


Can anybody help me with how I can be directed to PHP_exercises folder I created in C:\xampp\htdocs using XAMPP? And how I can make hitting localhost stop directing me to E_Shop as default, and direct me to XAMPP file directories?

Upvotes: 0

Views: 289

Answers (1)

Ken Lee
Ken Lee

Reputation: 8073

You should choose a root folder first, say "c:/xampp/htdocs"

So, please change

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/E_Shop"

to

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs"

Restart your httpd and then visit the following two links to see the effect:

a) http://localhost/E_shop

(assuming that you have an index.php inside the E_shop folder)

b) http://localhost/PHP_exercises/yourphp.php

(assuming that you have an yourphp.php inside the PHP_exercises folder)

Upvotes: 1

Related Questions