PHP code example of samsonasik / redirect-handler-module

1. Go to this page and download the library: Download samsonasik/redirect-handler-module library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samsonasik / redirect-handler-module example snippets


$redirect = '/foo'; // may be a variable from GET
return $this->redirect()->toUrl($redirect);

return [
    'redirect_handler_module' => [
        'allow_not_routed_url' => false,
        'default_url' => '/',
        'options' => [
            'exclude_urls' => [
                // 'https://www.github.com/samsonasik/RedirectHandlerModule',
            ], // to allow excluded urls to always be redirected
            'exclude_hosts' => [
                // 'www.github.com'
            ],
        ],
    ],
];

class Module
{
    public function onBootstrap($e)
    {
        $app           = $e->getApplication();
        $eventManager  = $app->getEventManager();
        $sharedManager = $eventManager->getSharedManager();

        $sharedManager->attach('RedirectHandlerModule\Controller\Plugin\Redirect', 'redirect-same-url', function() {
            die('You need to use different URL for Redirect');
        });

        $plugin = $app->getServiceManager()->get('ControllerPluginManager')->get('redirect');
        $plugin->setEventManager($eventManager);
    }
}

return [
    'modules' => [
        // ...
        'RedirectHandlerModule',
    ],
];