BeforeRedirectMatchDomainEvent 

The PSR-14 event \TYPO3\CMS\Redirects\Event\BeforeRedirectMatchDomainEvent allows extensions to implement a custom redirect matching upon the loaded redirects or return the matched redirect record from other sources.

Example: Match a redirect with custom logic 

EXT:my_extension/Classes/Redirects/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Redirects\EventListener;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Redirects\Event\BeforeRedirectMatchDomainEvent;

#[AsEventListener(
  identifier: 'my-extension/before-redirect-match-domain',
)]
final readonly class MyEventListener
{
  public function __invoke(BeforeRedirectMatchDomainEvent $event): void
  {
    $matchedRedirectRecord = $this->customRedirectMatching($event);
    if ($matchedRedirectRecord !== null) {
      $event->setMatchedRedirect($matchedRedirectRecord);
    }
  }

  private function customRedirectMatching(BeforeRedirectMatchDomainEvent $event): ?array
  {
    // @todo Implement custom redirect record loading and matching. If
    //       a redirect based on custom logic is determined, return the
    //       :sql:`sys_redirect` tables conform redirect record.

    // Note: Below is simplified example code with no real value.
    $record = BackendUtility::getRecord('sys_redirect', 123);

    // Do custom matching logic against the record and return matched
    // record - if there is one.
    if ($record /* && custom condition against the record */) {
      return $record;
    }

    // Return null to indicate that no matched redirect could be found
    return null;
  }
}
Copied!

API 

final class BeforeRedirectMatchDomainEvent
Fully qualified name
\TYPO3\CMS\Redirects\Event\BeforeRedirectMatchDomainEvent

This event is fired in \TYPO3\CMS\Redirects\Service\RedirectService->matchRedirect() for checked host and wildcard host "*".

It can be used to implement a custom match method, returning a matchedRedirect record with eventually enriched record data.

getDomain()
Return description

Request domain name (host)

Returns
string
getPath()
Return description

Request path

Returns
string
getQuery()
Return description

Request query parameters

Returns
string
getMatchDomainName()
Return description

Domain name which should be checked, and getRedirects() items are provided for

Returns
string
getMatchedRedirect()
Return description

Returns the matched sys_redirect record or null

Returns
array|null
setMatchedRedirect(array|null $matchedRedirect)
param $matchedRedirect

Set matched sys_redirect record or null to clear prior set record