【发布时间】:2018-05-09 08:00:36
【问题描述】:
我在访问WAMP 中的虚拟主机时遇到了一个奇怪的问题。
我通过在server configuration 页面中的wampserver 中定义来定义我的虚拟主机(它调用mvc.dev)。步骤与我在下面解释的完全相同:
1-首先,进入服务器配置页面,选择Add a virtual host
2- 因为我项目中的index.php在C:\wamp64\www\mvcdev\public path,所以我为我的虚拟主机填写了相关字段,然后开始创建虚拟主机。
3- 它已正确创建,并且 wamp 服务器想要手动重新启动 DNS。我像这样从 wamp 服务器菜单重新启动它:
4- 重新启动后,我检查 localhost 页面。说明mvc.dev创建正确,没有任何问题
5- 问题出现在这里,当我单击 mvc.dev 或在浏览器的地址栏中键入它来访问我的虚拟主机时,它会导致下载文件而不是加载 index.php 文件。我对这个问题感到非常沮丧,我不知道如何解决这个问题。为什么会导致下载 hex 文件而不是执行 URL?
这个文件是一个十六进制文件,每次我在url中输入mvc.dev,它就会开始下载这个文件
为了您的信息,我还通过手动定义虚拟主机对其进行了测试。我把相关代码放在httpd-vhosts.conf中,然后在host中定义mvc.dev,然后在restart DNS中,但结果和我之前解释的一样,我根本无法访问我的虚拟主机。你可以在下面看到它:
host 文件中的配置:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 mvc.dev
::1 mvc.dev
httpd-vhosts.conf的配置:
#
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mvc.dev
DocumentRoot c:/wamp64/www/mvcdev/public
<Directory "c:/wamp64/www/mvcdev/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
我该如何解决这个问题?
注意:我也一一检查过,但我无法解决我的问题: project-links-do-not-work-on-wamp-server
.htaccess 文件是
# Remove the question mark from the request but maintain the query string
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
index.php中的代码是
echo 'Request URL is: '.$_SERVER['QUERY_STRING'];
//require '../core/Router.php';
require "../vendor/autoload.php";
$router = new Core\Router();
$router->add('/','HomeController@index');
【问题讨论】:
-
我看到您在 DocumentRoot 文件夹中有一个
.htaccess文件!这个.htaccess文件中有什么内容? -
你真的不应该把
Require all granted给你的本地主机虚拟主机 -
这是为了在不输入 index.php 的情况下接受查询字符串: # 从请求中删除问号,但保留查询字符串 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L,QSA]
-
一件事,我在没有.htaccess文件的情况下检查,但结果是一样的
-
需要部分由 wamp 添加(当我像上面解释的那样创建它时)
标签: apache wamp virtualhost wampserver