【发布时间】:2020-01-21 20:27:58
【问题描述】:
该网站是 html,我有 3 个 .html 文件,其中有 3 个同名目录。顺便说一句,它在 ubuntu 18 上的 apache2
所以...... 文件1.html /文件1 文件2.html /file2 以此类推。
如果您不关闭 .htaccess 文件中的文件扩展名,则没有问题。但是当这样做时,目录被提供并且你得到一个错误。所以这是我尝试使用 DirectorySlash Off 的 .htaccess 配置。此文件中还有其他一些内容,但我想我会保留所有内容,以防这里发生相关的因果关系。
# BEGIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Options +MultiViews
DirectorySlash Off
# Rewrite to file when file and directory both exist with the same name
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.]+)$ $1.html [L]
# Allows files to be loaded without extensions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
# Removes the file extensions
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Redirects from products to product directory
RewriteRule ^products/(.*)$ /product/$1 [R=301,NC,L]
</IfModule>
# END
【问题讨论】: