动态目录索引(正则表达式目录索引?)
Dynamic DirectoryIndex (Regex DirectoryIndex?)
在 Apache 中,是否可以有一个 dynamic/regex DirectoryIndex 指令?
普通 DirectoryIndex 可以:
server/DIRECTORY1 --> server/DIRECTORY1/index.html
server/DIR1/DIR2 --> server/DIR1/DIR2/index.html
...
etc
但我将如何完成:
server/DIRECTORY1 --> server/DIRECTORY1/DIRECTORY1.html
server/DIR1/DIR2 --> server/DIR1/DIR2/DIR2.html
...
etc
我想要这个是因为我在编辑器中打开了很多索引文件,很难区分这些选项卡,因为它们都命名为索引。
- 我更喜欢在
httpd.conf
中适用于整个网站的内容
- 我想保留
mod_dir
具有的 with/without 尾部斜线检测。
- 我使用
mod_rewrite
的尝试往往会弄乱最后的 URI 变量 :(
您可以将此代码放在 httpd.conf
(mod_rewrite 块中)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}///\.html -f
RewriteRule ^/?(.+?)/([^/]+)/?$ ///.html [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}//\.html -f
RewriteRule ^/?([^/]+)/?$ //.html [L]
在 Apache 中,是否可以有一个 dynamic/regex DirectoryIndex 指令?
普通 DirectoryIndex 可以:
server/DIRECTORY1 --> server/DIRECTORY1/index.html
server/DIR1/DIR2 --> server/DIR1/DIR2/index.html
...
etc
但我将如何完成:
server/DIRECTORY1 --> server/DIRECTORY1/DIRECTORY1.html
server/DIR1/DIR2 --> server/DIR1/DIR2/DIR2.html
...
etc
我想要这个是因为我在编辑器中打开了很多索引文件,很难区分这些选项卡,因为它们都命名为索引。
- 我更喜欢在
httpd.conf
中适用于整个网站的内容
- 我想保留
mod_dir
具有的 with/without 尾部斜线检测。 - 我使用
mod_rewrite
的尝试往往会弄乱最后的 URI 变量 :(
您可以将此代码放在 httpd.conf
(mod_rewrite 块中)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}///\.html -f
RewriteRule ^/?(.+?)/([^/]+)/?$ ///.html [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}//\.html -f
RewriteRule ^/?([^/]+)/?$ //.html [L]