0

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

现在我在 XAMPP 文件夹的文件夹中创建了另一个文件夹,名称与我PHP_execises创建的位置相同,我在里面创建了一个 PHP 文件,这就是您可能猜到的问题:在浏览器的 URL 栏中,点击弹出一个URL 错误,单独点击 localhost,将我定向到默认文件夹,而不是 XAMPP 文件目录!E_ShophtdocsPHP_exerciseslocalhost/PHP_exercisesE_Shop

我检查了我的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>


谁能帮助我如何将我定向到使用 XAMPPPHP_exercises创建的文件夹?C:\xampp\htdocs以及如何使点击 localhost 停止将我定向E_Shop为默认值,并将我定向到 XAMPP 文件目录?

4

1 回答 1

1

你应该先选择一个根文件夹,比如“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)

于 2021-06-13T17:13:55.293 回答