BMM
BMM

Reputation: 710

htaccess redirect rule for changing part of url

I am trying to write an htaccess conditional redirect rule, but with no luck so far.

How can I use an htaccess redirect to redirect

http://www.domain.tld/en/oldpath/something/
http://www.domain.tld/en/oldpath/somethingelse/

to, respectively

http://www.domain.tld/en/newpath/something/
http://www.domain.tld/en/oldpath/somethingelse/

?

Is there a rule I can use to redirect "oldpath" to "newpath" whatever part of an url precedes or follows it?

Thank you for your help.

Upvotes: 1

Views: 58

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use:

RedirectMatch 302 ^(.*)/oldpath/(.*)$ $1/newpath/$2

Upvotes: 2

Related Questions