From 1ddf443c813db84b591804297aecb2e90a97f05b Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Mon, 10 Aug 2026 11:27:35 +0100 Subject: [PATCH 1/2] Redirect URLs from WP mailings --- Civi/Standalone/WebEntrypoint.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Civi/Standalone/WebEntrypoint.php b/Civi/Standalone/WebEntrypoint.php index 2ad363f28d57..ce4d72773aea 100644 --- a/Civi/Standalone/WebEntrypoint.php +++ b/Civi/Standalone/WebEntrypoint.php @@ -53,6 +53,9 @@ public static function invoke(): void { // Remove empty path segments, a//b becomes equivalent to a/b $args = array_values(array_filter($args)); + // Redirect urls from WP mailings + self::wpredirect($parts[0] ?? '', $parts[1] ?? ''); + // if request is for any path that doesn't start civicrm, // throw 404 before we waste any effort doing anything else // (may well be spam) @@ -95,6 +98,26 @@ public static function invoke(): void { print \CRM_Core_Invoke::invoke($args); } + /** + * Redirect URLs from old mailings sent before migration from WordPress + * + * @param string $path + * @param string $params + * @return void + */ + public static function wpredirect($path, $params) { + if (preg_match('/^\/wp-content\/uploads\/civicrm\/persist\/contribute\/images\/(.*)/', $path, $matches)) { + \CRM_Utils_System::redirect('/public/media/images/' . $matches[1]); + } + if (preg_match('/^\/wp-content\/uploads\/civicrm\/(mosaico_tpl\/.*)/', $path, $matches)) { + \CRM_Utils_System::redirect('/public/' . $matches[1]); + } + if ($path === '/civicrm/' && $params && + preg_match('/^civiwp=CiviCRM\&q=civicrm\/mailing\/url\&(u=\d+\&qid=\d+)/', $params, $matches)) { + \CRM_Utils_System::redirect('/civicrm/mailing/url?' . $matches[1]); + } + } + public static function installer(): void { \Civi\Setup::assertProtocolCompatibility('1.0'); From c8c649972d77fbc2d02375d180a70071f1488717 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Tue, 11 Aug 2026 11:57:56 +0100 Subject: [PATCH 2/2] Improve readability --- Civi/Standalone/WebEntrypoint.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Civi/Standalone/WebEntrypoint.php b/Civi/Standalone/WebEntrypoint.php index ce4d72773aea..aa260cd03779 100644 --- a/Civi/Standalone/WebEntrypoint.php +++ b/Civi/Standalone/WebEntrypoint.php @@ -106,14 +106,14 @@ public static function invoke(): void { * @return void */ public static function wpredirect($path, $params) { - if (preg_match('/^\/wp-content\/uploads\/civicrm\/persist\/contribute\/images\/(.*)/', $path, $matches)) { + if (preg_match('@^/wp-content/uploads/civicrm/persist/contribute/images/(.*)@', $path, $matches)) { \CRM_Utils_System::redirect('/public/media/images/' . $matches[1]); } - if (preg_match('/^\/wp-content\/uploads\/civicrm\/(mosaico_tpl\/.*)/', $path, $matches)) { + if (preg_match('@^/wp-content/uploads/civicrm/(mosaico_tpl/.*)@', $path, $matches)) { \CRM_Utils_System::redirect('/public/' . $matches[1]); } if ($path === '/civicrm/' && $params && - preg_match('/^civiwp=CiviCRM\&q=civicrm\/mailing\/url\&(u=\d+\&qid=\d+)/', $params, $matches)) { + preg_match('@^civiwp=CiviCRM\&q=civicrm/mailing/url\&(u=\d+\&qid=\d+)@', $params, $matches)) { \CRM_Utils_System::redirect('/civicrm/mailing/url?' . $matches[1]); } }