如果我把下面一行在index.html
文件,以讓Apache包括index.php
文件:如何讓Apache服務於index.php而不是index.html?
<?php include("/Live/ls_client/index.php"); ?>
參觀index.html
頁面顯示我:
<!--?php include("/Live/ls_client/index.php"); ?-->
這是爲什麼?爲什麼它實際上不包含PHP文件?
如果我把下面一行在index.html
文件,以讓Apache包括index.php
文件:如何讓Apache服務於index.php而不是index.html?
<?php include("/Live/ls_client/index.php"); ?>
參觀index.html
頁面顯示我:
<!--?php include("/Live/ls_client/index.php"); ?-->
這是爲什麼?爲什麼它實際上不包含PHP文件?
正如其他人所指出的,很可能您沒有設置.html
來處理php代碼。
話雖如此,如果您所做的只是使用index.html
來包含index.php
,您的問題可能應該是'我如何使用index.php
作爲索引文件?
在這種情況下,爲Apache(httpd.conf文件),搜索DirectoryIndex
和替換該行(如果你有dir_module
啓用只會工作,但是這是在默認安裝大部分):
DirectoryIndex index.php
如果使用其他目錄索引,列出它們的優先順序即
DirectoryIndex index.php index.phtml index.html index.htm
PHP只能在.php
文件擴展名上使用。
如果您使用的是Apache,則還可以在您的httpd.conf
文件中設置PHP擴展。你必須找到行:
AddType application/x-httpd-php .php .html
^^^^^
,並添加多少擴展,這應該與PHP解釋器,只要你想讀。
雖然你可以* *添加'.html'擴展到PHP處理程序在你的Apache配置 – 2013-04-24 12:30:59
OK , 我會嘗試。 thx – 2013-04-24 12:31:44
@dirt,right,added。 – Shoe 2013-04-24 12:33:07
截至今天(2015年8月,第1),Apache2
在Debian Jessie
,你需要編輯:
[email protected]:/etc/apache2/mods-enabled$ vi dir.conf
,並更改該行的順序,把index.php的第一位置:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
你也可以使用'DirectoryIndex index.php index.html' - 如果這些在一臺服務器上混合使用,則很有用。 – MarioP 2013-04-24 12:52:36
編輯該文件。 – 2013-04-24 12:57:06
work!,謝謝:) – 2013-04-24 13:12:29