【问题标题】:apache directory index file not showingapache目录索引文件未显示
【发布时间】:2018-07-16 14:27:10
【问题描述】:

我想在 htaccess 中做两件事:

  1. 从 php 文件中去除扩展
  2. 当 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)

标签: regex apache .htaccess


【解决方案1】:

更新

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

到:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

解决了问题

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 2017-03-13
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2014-04-20
    • 1970-01-01
    相关资源
    最近更新 更多