【发布时间】:2018-07-16 14:27:10
【问题描述】:
我想在 htaccess 中做两件事:
- 从 php 文件中去除扩展
- 当 url 为 site/com/dir/ 时提供目录/索引
当前代码
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
/dir/ --> /dir/index 是默认的 apache 行为,但是 rewriteRule 打破了这个逻辑。 如何设置 rewriteRule 以从文件中剥离扩展名而不破坏 dir --> dir/index 逻辑?
【问题讨论】:
-
但是您希望这些规则中的哪一个能够执行所需的重定向?
-
据我所知,apache 默认重定向到目录索引,其中一个规则是阻止它,我不知道为什么
-
文件
/promotion/index.html存在吗? -
/promotion/index.php 存在。 /promotion/ 目录中的 .htaccess 也与“DirectoryIndex index.php”一起存在
-
RewriteRules 在DirectoryIndex之前被评估,所以你的最后一条规则导致promotion.php(或者甚至promotion/.php,除非你有DirectorySlash Off)