如果服务器返回 404,则 htaccess 重新编辑
例如,我有一个页面 http://www.f1u.org/en /其有趣/166-cricri。 如何编写规则:如果该页面存在 - 打开它。 如果返回 404,则重定向到 http://www.f1u.org/its-interesting /166-cricri
For example I have a page http://www.f1u.org/en/its-interesting/166-cricri.
How to write rule: if that page exists - open it.
If it returns 404, then redirect to http://www.f1u.org/its-interesting/166-cricri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
.htaccess
文件中使用此行use this line in
.htaccess
file听起来您希望 apache 服务器向前查看当前 URL 是否存在,如果不存在,则重定向它们。我认为您也许可以使用 mod_rewrite 来完成此任务。
我的第一次尝试是这样的:
我会注意到我还没有尝试过,所以语法和效果可能会略有偏差,你需要小心不要让自己陷入无限循环,或者最终产生太多子请求(因为这可能会影响服务器的性能)。但希望它能为您提供一个玩的起点。或者,mod-rewrite 也可以(取决于服务器权限)让您调用脚本来确定重写,这也可以是一个选项。
It sounds like you want the apache server to look ahead to see if the current URL exists, if not, redirect them. I think you might be able to use mod_rewrite to accomplish this.
My first stab at it would be something like:
I'll note that I haven't tried it so the syntax and effects could be slightly off, and you'd need to be careful that you don't put yourself into an infinite loop, or wind up with too many subrequests (as that could impact the performance of your server). But hopefully it'll give you a starting point to play with. Alternatively mod-rewrite could (depending on server permissions) let you invoke scripts to determine rewrites as well, which could be an option as well.