2017-07-17 46 views
1

我在Windows机器上本地设置了一个新站点进行测试。在文档根目录中,如果我有一个index.html,它将在浏览器中正常使用。如果我将其重命名为index.php,浏览器将不会收到任何内容。服务器端没有提出错误。我试图理解为什么。Apache 2.4:PHP文件没有被发送到浏览器

虚拟主机

<VirtualHost *:80> 
    DocumentRoot "C:\websites\learn" 
    ServerName learn.loc 

    LogLevel alert rewrite:trace2 

    #PHP SETTINGS 
    php_value auto_prepend_file "C:\websites\learn\noop.php" 
    php_value open_basedir "C:\websites\learn" 

    <Directory "C:\websites\learn">  
     Options Indexes FollowSymLinks 
     AllowOverride All 
     Require all granted 
    </Directory> 

</VirtualHost> 

这里是.htaccess文件驻留在文档根:

RewriteEngine on 
#point to javascript learning project 
RewriteRule ^js /javascript 
RewriteRule ^js/(.*) /javascript/$1 

下面是当我加载learn.loc/javascript产生的mod_rewrite日志(该文件夹具有一个index.php文件)

[initial] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/ 
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.html 
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.htm 
[subreq] [perdir C:/websites/learn/] pass through C:/websites/learn/javascript/index.php 

没有添加到Apache或PHP错误日志;浏览器本身接收status code 200,具有以下响应头

Date:   "..." 
Server:   "Apache/2.4.16 (Win32) PHP/5.6.23" 
X-Powered-By: "PHP/5.6.23" 
Content-Length: "0" 
Keep-Alive:  "timeout=5, max=100" 
Connection:  "Keep-Alive" 
Content-Type: "text/html; charset=UTF-8" 

的响应体是空字符串一起。就像我说的,如果我将文件重命名为index.html,会显示内容(香草html文件)。可能会发生什么?

回答

0

我想通了。那只是我粗心大意。问题是这条线从虚拟主机配置:

php_value auto_prepend_file "C:\websites\learn\noop.php" 

更具体地说,什么应该是一个空操作,确实是一个执行的杀手。

noop.php

<?php 
exit; // <- exits not just this script but all of PHP and returns to the browser 

一旦我删除了2号线,东西才能回来。这也解释了为什么将index.php重命名为index.html得到了一些结果:它完全使PHP退出了循环。