1

我有一个目录和一个同名的文件,例如:

foo.html

富/

我的 .htaccess 文件设置为在地址栏中隐藏文件扩展名,因此当我请求 www.example.com/foo 时,它应该显示 foo.html 文件。但是,由于存在同名目录 - 不会显示 foo.html 文件,而是显示目录,如 www.examplecom/foo/

如何确保文件优先于同名目录?我已经搜索了几个小时,但没有找到可行的解决方案。我试过禁用 DirectorySlash 没有运气。

我的 .htaccess 文件:

RewriteEngine On
DirectorySlash Off

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]

运行 Apache/2.4.7 (Ubuntu) 服务器

4

1 回答 1

1

将您的规则替换为:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]

你也不需要DirectorySlash Off线。

于 2014-07-13T05:50:07.137 回答