0

As following Magento 2: How to define Scope For Router.php we already have

if ($condition->getRedirectUrl()) {
    $this->response->setRedirect($condition->getRedirectUrl());
    $request->setDispatched(true);
    return $this->actionFactory->create(Redirect::class);
}

But I have some condition due to that redirect other ways.

$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$redirectURL = $request->getServer('REQUEST_SCHEME')."://".$request->getServer('SERVER_NAME').$request->getServer('REQUEST_URI');
$resultRedirect->setUrl($redirectURL);

Above is giving BLANK page.

$this->_redirect($redirectURL);

Above one is giving

Call to undefined method Custom\Module\Controller\Router::_redirect() in D:\wamp\www\magento2\app\code\Custom\Module\Controller\Router.php on line 116

1

Finally got the answer.

Thanks to https://github.com/zoransalamun/magento2-custom-router/blob/master/Controller/Router.php

Below is the code for Router.php

// START REDIRECT
        if (strpos($request->getServer('REQUEST_URI'), 'myList') !== false) {
                $request->setModuleName('myModule')->setControllerName('mylist')->setActionName('index');
                return $this->actionFactory->create(
                                'Magento\Framework\App\Action\Forward', ['request' => $request]
                );
            }
// STOP REDIRECT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.