2015-12-11 26 views
2

嗨,我正在一个项目,我有两个索引文件的根,一个是index.php和其他是index.html。我想o设置默认页面index.php,如果它不可用,那么它应该为index.html工作。 我在互联网上搜索了很多,并找到了以下解决方案。无法在apache2中设置默认索引页[Debian 7.1]

DirectoryIndex index.php index.html 

我使用我的网站上这样的代码:

<Directory "/home/zhengyu/webroot/engine5g/rentown.com/"> 
      DirectoryIndex index.php index.html default.htm 
</Directory> 

我也曾尝试另一种方式:

<Directory "/home/zhengyu/webroot/engine5g/rentown.com/"> 
      DirectoryIndex index.php index.html 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride None 
      DirectoryIndex index.php index.html 
      Order allow,deny 
      allow from all 
</Directory> 

但他们没有工作,它总是让index.php文件默认,但是当它不可用时它不会加载index.html。

如果我先编写index.html然后index.php,然后加载index.html,但如果index.html不可用,则不加载index.php。

总之,我们可以说首选项不起作用。

回答

1

您可以指定多个文件名,Web服务器将搜索每个文件,直到找到匹配项。考虑这个例子指令:

写入到这个根你的htaccess文件:

DirectoryIndex index.php index.html 

在这个指令,当访问者请求目录名,网络 服务器首先查找的index.php文件文件。如果找不到 index.php文件,它会查找index.html文件,依此类推,直到 找到匹配项或用尽文件进行搜索。

或者尝试这种方式

# Example A: Set index.html as an index page, then add index.php to that list as well. 
<Directory "/foo"> 
    DirectoryIndex index.html 
    DirectoryIndex index.php 
</Directory> 

# Example B: This is identical to example A, except it's done with a single directive. 
<Directory "/foo"> 
    DirectoryIndex index.html index.php 
</Directory> 

# Example C: To replace the list, you must explicitly reset it first: 
# In this example, only index.php will remain as an index resource. 
<Directory "/foo"> 
    DirectoryIndex index.html 
    DirectoryIndex disabled 
    DirectoryIndex index.php 
</Directory> 

来源:

+0

我已经试过这个,但它不起作用 –

+0

@Insomania你可以在这里粘贴你的htacess规则吗? – Suresh

+0

@Insomania我认为你有路径问题'/ home/zhengyu/webroot/engine5g/rentown.com /';尝试改变它。 – Suresh