Regular Expression Wordpress redirection plugin
-
21-12-2019 - |
Question
I'm using the Redirection plugin to Wordpress, but can't get this regex to work. I'm not an expert on regex at all, so I guess I'm doing something wrong.
/(.*)/(.*)/?rel=old
/$1/$2/?rel=new
When doing this I end up with: http://domain.se/something/somestuff/?/?rel=new
It should be: http://domain.se/something/somestuff/?rel=new
Why is it not working and what is that extra /?/
Solution
Looks like you forgot to escape the ?
.
/(.*)/(.*)/\?rel=old
/$1/$2/?rel=new
In regex, ?
means match the preceding character/group zero or one times - so your original regex was looking for an optional /
character immediately before rel=old
. Of course it didn't find this, and so instead the text matched by the second capture group expanded to encompass the /?
characters before rel=old
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow