.htaccess redirect without redirect loop

夙愿已清 提交于 2019-12-13 01:42:25

问题


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/(.*) http://www.domain.com/example/about/$1 [R=301,L].

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

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 http://www.domain.com/about/(.*) http://www.domain.com/example/about/$1 [R=301,L].

However that didn't work.

Does anyone have a straight forward solution for this.

Thanks


回答1:


This rule should work with anchors in regex pattern:

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

^/?about will only match http://www.domain.com/about/ but not http://www.domain.com/example/about/



来源:https://stackoverflow.com/questions/32317493/htaccess-redirect-without-redirect-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!