如何让 Apache 服务 index.php 而不是 index.html?

2022-01-25 00:00:00 include php apache

如果我将以下行放在 index.html 文件中,以使 Apache 包含 index.php 文件:

If I put the following line in a index.html file, to make Apache include the index.php file:

  <?php include("/Live/ls_client/index.php"); ?>    

访问 index.html 页面告诉我:

<!--?php include("/Live/ls_client/index.php"); ?-->

这是为什么呢?为什么它实际上不包含 PHP 文件?

Why is that? Why doesn't it actually include the PHP file?

推荐答案

正如其他人所指出的,您很可能没有设置 .html 来处理 php 代码.

As others have noted, most likely you don't have .html set up to handle php code.

话虽如此,如果您所做的只是使用 index.html 来包含 index.php,那么您的问题可能应该是我该如何使用 index.php 作为索引文件?

Having said that, if all you're doing is using index.html to include index.php, your question should probably be 'how do I use index.php as index document?

在这种情况下,对于 Apache (httpd.conf),搜索 DirectoryIndex 并将该行替换为该行(仅当您启用 dir_module 时才有效,但这是大多数安装默认):

In which case, for Apache (httpd.conf), search for DirectoryIndex and replace the line with this (will only work if you have dir_module enabled, but that's default on most installs):

DirectoryIndex index.php

如果您使用其他目录索引,请按优先顺序列出它们,即

If you use other directory indexes, list them in order of preference i.e.

DirectoryIndex index.php index.phtml index.html index.htm

相关文章