dmk/mk30xlegacy

DMK auto redirects to legacy/mirror/stale environment.

Installs: 2 513

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 5

Forks: 0

Open Issues: 0

Type:typo3-cms-extension

1.0.0 2023-04-25 06:20 UTC

This package is auto-updated.

Last update: 2024-02-08 12:37:25 UTC


README

TYPO3 compatibility Latest Stable Version Total Downloads Build Status Code Coverage License

This TYPO3 extension performs automatic redirects to a legacy domain if the requested uri was not found at the TYPO3.

What it does in short:

  • Registers a middleware.
  • Checks the TYPO3 response for unavailable status code.
  • asks matchers for the uri to the new or old source to redirect to
    • PageTypeSuffixRemovalMatcher:
      Checks whether the url has a suffix and whether the url exists without an ending.
      (Core SiteMatcher finds the uri or a HEAD request returns 200 status code).
    • LegacyUriMatcher:
      Checks if the request uri is available at the legacy domain
      (returns 200 status code on HEAD request).
  • Performs a redirect to the new uri.

Installation

Install TYPO3 via composer.
From project root you need to run

composer require dmk/mk30xlegacy

Configuration

The base configuration is done by extension configuration.
Use The Admin Tools > Settings > Configure Extensions module to configure mk30xlegacy.

The configuration can be overridden by site configuration or site language configuration.
Use the Site Management > Sites module to configure the extension.

  • enabled
    Enables the legacy redirect middleware. (default: 1)
  • responseMatchPattern
    Response match pattern: Regex to match with current request http response code to perform legacy redirect. (default: [345]\d\d)
  • suffixRemovalSuffixes
    Page Type Suffixes: A comma seperated list of suffixes to remove from request uri. (default: html,htm,xhtml)
  • redirectDomain
    Redirect Domain: Domain to performe the legacy redirect to.
  • redirectDomainAvailabilityMatchPattern
    Legacy availability match pattern: Regex to match with http response code from legacy check. On match a redirect to legacy domain will be performed. (default: 2\d\d)
  • redirectResponseStatusCode
    Redirect Response HTTP-Status-Code: The HTTP-Status Code used for redirects to legacy domain. (default: 307)

Add Custom Matcher

The redirect middleware uses a matcher registry, so custom matchers can be developed.

class CustomMatcher implements MatcherInterface
{
    public function isMatchableResponse(ResponseInterface $response): bool
    {
        // check here if this matcher is enabled for the typo3 response!
        return true;
    }

    public function matchRequest(ServerRequestInterface $request, ResponseInterface $response): UriResult
    {
        $result = new UriResult();
        // add your custom stuff here,
        // to create an uri result (for redirect)
        // depending on the request and response
        return $result
    }
}

Add the custom matcher in your Services.yaml:

    DMK\MyAwesomeExtension\Routing\Matcher\CustomMatcher:
        tags:
            -
                name: 'mk30xlegacy.routing.matcher'
                priority: 100

Custom legacy uri manipulation

You can register an event listener before the availability check of the LegacyUriMatcher is performed, to manipulate the legacy url by your own (we recommend to use a custom matcher instead!):

class LegacyUriMatchEventListener
{
    public function __invoke(UriMatchPreAvailabilityCheckEvent $event): void
    {
        $uri = $event->getResult()->getUri();
        // manipulate the url here, add query parameters for example.
        $uri = $uri->withQuery('?legacy=redirect&'.$uri->getQuery());
        $event->getResult()->setUri($uri);
    }
}

Add the custom listener in your Services.yaml:

services:
    DMK\MyAwesomeExtension\Event\EventListener\LegacyUriMatchEventListener:
        tags:
            -
                name: 'event.listener'
                identifier: 'MyAwesomeLegacyUriMatchEventListener'
                event: DMK\Mk30xLegacy\System\Event\UriMatchPreAvailabilityCheckEvent