htaccess 重写单个文件 [英] htacces rewrite single file

查看:75
本文介绍了htaccess 重写单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to rewrite a specific file on my website to another one by using htaccess:

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

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

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

This is the .htaccess code i'm using based on snippets i found on the internet. Somehow this is not working, the server is returning a 404-Not-found error.

我看不出与据说有效的示例有任何区别,例如使用 htaccess 重写特定文件的路径

I can't see any difference with example's that are said to work, like in Rewriting path for a specific file using htaccess

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

If I place file.html in the root-folder, I can view it. So the rewrite definitely is not happening.

推荐答案

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

RewriteRule does not receive leading slash. Write so:

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

这篇关于htaccess 重写单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆