2013-04-24 78 views
24

如果我把下面一行在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文件?

回答

46

正如其他人所指出的,很可能您沒有設置.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 
+5

你也可以使用'DirectoryIndex index.php index.html' - 如果這些在一臺服務器上混合使用,則很有用。 – MarioP 2013-04-24 12:52:36

+0

編輯該文件。 – 2013-04-24 12:57:06

+0

work!,謝謝:) – 2013-04-24 13:12:29

7

PHP只能在.php文件擴展名上使用。

如果您使用的是Apache,則還可以在您的httpd.conf文件中設置PHP擴展。你必須找到行:

AddType application/x-httpd-php .php .html 
            ^^^^^ 

,並添加多少擴展,這應該與PHP解釋器,只要你想讀。

+0

雖然你可以* *添加'.html'擴展到PHP處理程序在你的Apache配置 – 2013-04-24 12:30:59

+0

OK , 我會嘗試。 thx – 2013-04-24 12:31:44

+0

@dirt,right,added。 – Shoe 2013-04-24 12:33:07

6

截至今天(2015年8月,第1),Apache2Debian 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 
相關問題