配置htaccess目录索引文件

问题描述:

场景: 我创建了此htacces文件以重定向子域。到目前为止它的工作。配置htaccess目录索引文件

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
Options +Indexes 

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} ^(.*)\.example\.net$ [NC] 
RewriteRule ^(.*) http://example.net/%1/$1 [P,NC,QSA] 
</IfModule> 

问题:

它迫使服务器以请求的任意index.php不存在。我所拥有的是index.html,所以我越来越:

Error 404: /xyz/index.php was not found on this server

我尝试添加:

DirectoryIndex index.html index.php [L] 

但只有第一个参数被接受,第二个被忽略(为什么?)。只要存在,AFAIK就应该接受其中的任何一种。

+0

删除directoryindex中的[L],因为这是无效的,并且DirectoryIndex将始终使用第一个参数(如果存在第一个参数)。如果你有两个在同一个目录中,它将始终使用第一个。它只是按照列表中的内容来检查它是否存在。 –

+0

它不起作用。因为它只评估第一个参数,而忽略第二个参数。例如。包含index.php的目录将抛出404。每个目录BTW只有1个索引,不管是HTML还是PHP。 – Ariel

试试这个: 我复制此内容并正常工作。

<IfModule mod_rewrite.c> 

    RewriteEngine on 

    RewriteRule ^$ public/ [L] 

    RewriteRule (.*) public/$1 [L] 

</IfModule> 

您应该将'public'更改为您的文件夹。

+0

没有。这抛出'坏请求' – Ariel