htaccess 重写单个文件

编程入门 行业动态 更新时间:2024-10-28 16:26:33
本文介绍了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 重写单个文件

本文发布于:2023-10-31 16:53:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   文件   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!