1

I need to redirect all traffic for a suspended site and what I have tried so far is installing the redirect plugin and adding a redirect (tools->redirection->add new

source: ^/(?!.*login.*|under_construction)(.*)
target: /under_construction

But while it redirects all traffic to under_construction correctly, and does not redirect under_construction (recursively), the login exclusion isn't working so it also redirects the login to under_construction, so I can't log in or out.

https://example.com/wordpress/wp-login.php to https://example.com/under_construction

Fortunately, it wouldn't let me log out, and did not affect the other admin pages, so I was able to disable it. :-)

  • The regex could be simplified a bit, but otherwise, it looks OK to me. I think the problem is "something else". Are URLs that contain "login" the only required exception? – MrWhite Nov 29 '18 at 0:34
  • @MrWhite yeah, and it's a bit odd, as none of the other /wordpress/ pages are redirected, just the login – Wyrmwood Nov 29 '18 at 2:01
  • So, it's not even redirecting the pages that should be redirected? Presumably you are using the default config whereby WordPress is handling the redirection, not Apache (or Nginx)? – MrWhite Nov 29 '18 at 2:12
  • 1
    @MrWhite - with that regex enabled, it redirects all traffic to the correct page, but also redirects the login/logout page. – Wyrmwood Nov 29 '18 at 2:22
1

I'd recommend adjusting the parenthesis in your regex. Specifically, it isn't clear to me how much of the .*login.* is being viewed as a single group before the "or" (|). I'd put parenthesis around that and around under_construction for good measure.

You don't need parenthesis around the final .* because that will stand fine on its own and you are not using that as a capturing group.

Try: ^/(?!(.*login.*)|(under_construction)).*

  • Perfect. Works as intended. Thank you so much! – Wyrmwood Nov 29 '18 at 12:59
  • There must have been something else?! The additional parenthesis in this example make no difference in terms of whether the regex (PCRE) matches (or not). Alternation ("or") has very low precedence and * (quantifier) has very high precedence; .*login.* will be seen as "one group" regardless. The additional parens are arguably undesirable as they create two additional (unnecessary) capturing groups (1 and 2) that will always be empty. Maybe there was a caching issue? Or maybe the WP redirection plugin does something "funny" with the regex first (although that would seem unlikely)? – MrWhite Nov 29 '18 at 17:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.