How to use controller to redirect customers to another URL in Magento 2
In Magento 2, you can use the following code to redirect customers to another URL with the help of controller:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php namespace Dfe\Facebook\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { /** * @override * @see \Magento\Framework\App\Action\Action::execute() * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { return $this->resultRedirectFactory->create()->setUrl(rm_request('url')); } } |
Some examples from the core:
1 |
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl()); |
1 |
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]); |