Skip to content

Use with Blitz

Pierre Stoffe edited this page Mar 5, 2020 · 5 revisions

If you are using Blitz (or a similar cache plugin) you will notice that language redirections are not working anymore. This is because Blitz generates static pages and ends all requests before they can hit any other plugin, including Language Redirector.

As a solution we can listen to the EVENT_BEFORE_GET_RESPONSE Blitz event that gets triggered before Blitz returns a cached page, and hook Language Redirector there. See the code example below that you can add to your business logic.

use putyourlightson\blitz\services\CacheRequestService;

Event::on(
    CacheRequestService::class,
    CacheRequestService::EVENT_BEFORE_GET_RESPONSE,
    function (Event $event) {
        $languageRedirectorService = new LanguageRedirectorService();
        $languageRedirectorService->canRedirectVisitor();
    }
);```

This solution works with v1.3.2 of Language Redirector and above.
Clone this wiki locally