Regex To Match URL That Do Not Begin With String in WP Redirection Plugin

Currently, I’m using Redirection plugin in WordPress to redirect all URLs that contain question mark in this way:

Source: /(.*)?(.*)$
Target: /$1

This works well. It will redirect any link with a ?, such as /good-friends-are-great.html?param=x to /good-friends-are-great.html.

However, now I need to make an exception. I need to allow /friends to pass GET parameters, e.g. /friends?guest=1&event=chill_out&submit=2 OR /friends/?more_params, without the parameters being truncated.

I have tried modifying the regular expression in the plugin to:

Source: /(?!friends/?)?(.*)$
Target: /$1

But this didn’t work. With the above expression, any link with ? is no longer redirected.

Can you help? Thank you in advance.

PS: Sorry if this is a duplicate question. I’ve searched this website for similar questions but based on what I’ve read, I still can’t piece together the right solution.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.