为什么URL无法使用XAMPP进入其他文件夹目录?

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

我第一次使用 XAMPP 时,我创建了一个名为 E_Shop 的文件夹,自从我在我的 URL 地址中点击 localhost127.0.0.1我的浏览器栏,我被定向到这个我创建过一次的 E_Shop 文件夹,

现在我在创建 E_Shop 的相同位置创建了另一个名为 PHP_execises 的文件夹,在 XAMPP 文件夹的 htdocs 文件夹中,我创建了一个 PHP 文件 inside PHP_exercises,这就是您可能猜到的问题:在浏览器的 URL 栏中,点击 localhost/PHP_exercises 弹出 URL 错误,并且单独点击本地主机,默认情况下将我定向到 E_Shop 文件夹,而不是 XAMPP 文件目录!

我检查了我的 C:\Windows\System32\drivers\etc\hosts,里面有这个代码:

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

C:\xampp\apache\conf\extra\httpd-vhosts.conf里面是:

# 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 webmaster@dummy-host.example.com
    ##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 webmaster@dummy-host2.example.com
    ##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 admin@bookshop.com
    DocumentRoot "C:/xampp/htdocs/E_Shop"
    ServerName bookshop.com
    ErrorLog "logs/bookshop.com-error.log"
    CustomLog "logs/bookshop.com-access.log" common
</VirtualHost>


任何人都可以帮助我如何将我定向到我使用 XAMPP 在 C:\xampp\htdocs 中创建的 PHP_exercises 文件夹?以及如何让点击 localhost 停止默认将我引导至 E_Shop,并将我引导至 XAMPP 文件目录?

你应该先选择一个根文件夹,说“c:/xampp/htdocs”

所以,请更改

<VirtualHost *:80>
    ServerAdmin admin@bookshop.com
    DocumentRoot "C:/xampp/htdocs/E_Shop"

<VirtualHost *:80>
    ServerAdmin admin@bookshop.com
    DocumentRoot "C:/xampp/htdocs"

重启httpd,然后访问以下两个链接查看效果:

a) http:///localhost/E_shop

(假设您在 E_shop 文件夹中有一个 index.php)

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

(假设您在 PHP_exercises 文件夹中有一个 yourphp.php)