[英]Apache 2.4: PHP files are not being sent to the browser
我正在Windows機器上本地設置一個新站點進行測試。 在文檔根目錄中,如果我有index.html
它將毫無問題地提供給瀏覽器。 如果我將其重命名為index.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文件)。 可能會發生什么?
我想到了。 那只是我粗心。 問題出在Vhosts配置中的這一行:
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
一旦我刪除了第二行,一切就恢復了正常。 這也解釋了為什么將index.php
重命名為index.html
可以正常工作:PHP完全退出了循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.