2013-04-24 75 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 
相关问题