How to substitute part of a web path name via regex in order redirect it?

47 Views Asked by At

I never got familiar with regex, so I struggle!

I need an expression after a relaunch of my website (Wordpress) where I need to rename part of a folder name into a new expression like. I use "Redirection" as a plugin that asks for two parameters: source and target urls.

What has to get redirected? www.test.com/old/sometext -> www.test.com/new/sometext

I tried ro find the first: ^/old/(.*) and to replcae it by:/new/$1

Well, nothing happens... Help is welcome!

1

There are 1 best solutions below

0
On

Try:

\/old\/(.+)$

and replace with

/new/$1

See it on Regex101: https://regex101.com/r/WXEyaN/latest

The issues seem to be:

a) the ^ tells the regex to be anchored at the start of a line - omit it.

b) the / character needs to be escaped - instead write \/.