user310291
user310291

Reputation: 38180

Regex syntax for url redirection

I'm using this wordpress plugin for redirection which offers regex https://wordpress.org/plugins/redirection/

I've always been completely baffled with regex syntax so I tried this and it doesn't work

source:    ^/(.*)/blog/(.*)$
target;    ^/(.*)/(.*)$

for redirecting

http://example.com/anycategory/blog/anypage

to

http://example.com/anycategory/anypage

Upvotes: 0

Views: 316

Answers (1)

anubhava
anubhava

Reputation: 784898

You don't give regex in regex. You need to use back-reference of capturing groups from source and have it like this:

source:    ^/?([^/]+)/blog/(.*)$
target;    /$1/$2

Upvotes: 1

Related Questions