htaccess 重写单个文件

htacces rewrite single file

我想使用 htaccess 将我网站上的特定文件重写为另一个文件:

# General
RewriteEngine On
RewriteBase /
Options All -Indexes
Options +FollowSymLinks

# Rewrite file
RewriteRule ^/file.html$ /dir/file.html [L]

这是我根据在互联网上找到的片段使用的 .htaccess 代码。 不知何故这不起作用,服务器返回 404-Not-found 错误。

我看不出与据说有效的示例有任何区别,例如 Rewriting path for a specific file using htaccess

编辑: 如果我将 file.html 放在根文件夹中,我可以查看它。所以重写肯定不会发生。

RewriteRule 不接收前导斜杠。这么写:

RewriteRule ^file.html$ /dir/file.html [L]