2017-07-17 63 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退出了循環。