【问题标题】:configuring htaccess directory index file配置htaccess目录索引文件
【发布时间】: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


【解决方案1】:

试试这个: 我复制了这个并正常工作。

<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteRule    ^$    public/    [L]

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

</IfModule>

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

【讨论】:

  • 不。这会引发bad request
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-18
  • 2011-01-18
  • 2011-06-30
  • 2012-01-15
  • 2013-11-29
  • 2016-05-11
  • 2014-02-01
相关资源
最近更新 更多