Jack
Jack

Reputation: 383

.htaccess redirect without redirect loop

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

Upvotes: 1

Views: 157

Answers (1)

anubhava
anubhava

Reputation: 785156

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/

Upvotes: 1

Related Questions