【问题标题】:Can you change the DirectoryIndex of specific directories?您可以更改特定目录的 DirectoryIndex 吗?
【发布时间】:2012-07-27 06:47:33
【问题描述】:

我知道您可以在.htaccess 中使用DirectoryIndex example.html,但我需要更改特定目录的索引,如下所示:

DirectoryIndex /ex/index_file.html

DirectoryIndex /ex2/index_file2.html

有没有办法可以做到这一点?我不想将我正在尝试执行此操作的文件重命名为 index.html,因为它不是这样。您需要先登录,如果不是,它将重定向您;但我认为这看起来很草率。

【问题讨论】:

  • 我的意思是,假设我有 2 个单独的目录。 dir1dir2。对于dir1,我希望DirectoryIndex 为example.html,对于dir2,我希望DirectoryIndex 为another_example.html。这有帮助吗?
  • 哦,知道了,我想你可以在下面看到答案,我想应该可以解决

标签: apache .htaccess directoryindex


【解决方案1】:

您可以在每个需要不同目录索引的目录中创建一个 .htaccess。ex 目录中的 .htaccess 应包含:

DirectoryIndex index_file.html

ex2 中的 on 应该包含:

DirectoryIndex index_file2.html

您也可以在 Web 根目录的 .htaccess 中使用 <Directory>,只要您被允许覆盖它:

<Directory ex>
   DirectoryIndex index_file.html
</Directory>

<Directory ex2>
    DirectoryIndex index_file2.html
</Directory>

【讨论】:

  • 这解决了我的问题。 :) 我认为你可能能够做到这一点,我想我应该在发布问题之前尝试过;那好吧。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-04
  • 2018-12-10
  • 2013-01-15
  • 2011-03-07
  • 1970-01-01
  • 2019-09-06
  • 1970-01-01
相关资源
最近更新 更多