0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

6 Comments

what is the purpose of this here /?
That makes leading slash optional.
@anubhava how to restrict (.*) to letters only ? thanks.
You can change (.*) to ([a-zA-Z]+) to restrict to letters only.
@anubhava tried: ^/?([^/]+)/blog/([a-zA-Z]+)$ weirdly doesn't work anymore
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.