.htaccess重定向,无重定向循环

编程入门 行业动态 更新时间:2024-10-25 22:35:45
本文介绍了.htaccess重定向,无重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我肯定在那里有一个答案,但是它确实让我耳目一新,并且我讨厌与.htaccess重定向有关的任何事情.

Im sure there is an answer out there for this somewhere but its doing my head in and I hate anything to do with .htaccess redirects.

基本上我正在尝试这样做

Basically I am trying to do this

RewriteRule /about/(.*) www.domain/example/about/$1 [R=301,L].

问题在于,这导致重定向循环,因为从URL重定向到URL都包含"about".

Problem is that this results in a redirect loop because "about" is in both the redirected from and redirected to url.

id想要做的是拥有它,以便仅当根URL在/about/之前时才重定向.我确实尝试过这样做:

What id like to do is have it so that it will only redirect if the root url is before the /about/. I did try doing this with this:

RewriteRule www.domain/about/(.*) www.domain/example/about/$1 [R=301,L].

但是那没用.

有人对此有直接解决方案吗?

Does anyone have a straight forward solution for this.

谢谢

推荐答案

此规则应使用正则表达式模式中的锚点:

This rule should work with anchors in regex pattern:

RewriteRule ^/?(about/.*)$ /example/$1 [R=301,L,NC]

^/?about仅匹配www.domain/about/,而不匹配www.domain/example/about/

更多推荐

.htaccess重定向,无重定向循环

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

发布评论

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

>www.elefans.com

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