【问题标题】:htacces rewrite single filehtaccess 重写单个文件
【发布时间】:2015-05-03 15:23:02
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

    标签: .htaccess file rewrite


    【解决方案1】:

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

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

    【讨论】:

    • 这确实是问题所在(加上我不知道该文件将被执行多次,直到不再进行重写)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    相关资源
    最近更新 更多