【发布时间】:2016-03-27 22:40:23
【问题描述】:
场景: 我创建了这个 htacces 文件来重定向子域。到目前为止它有效。
<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 它应该接受其中任何一个,只要它们存在。
【问题讨论】:
-
从 directoryindex 中删除 [L] 无效,如果第一个参数存在,DirectoryIndex 将始终使用第一个参数。如果两者都在同一个目录中,它将始终使用第一个。它只是按照列表中的内容的顺序来检查它是否存在。
-
它不起作用。照原样它只评估第一个参数,而忽略第二个。例如。包含 index.php 的目录将抛出 404。顺便说一句,每个目录只有 1 个索引,无论是 HTML 还是 PHP。
标签: php .htaccess directoryindex