I have a site with 2 store views.

One of the views (lets call it store view X), should be accessible to only certain users, and parts of the store should be restricted when this store view is enabled.

For example, when a logged in user is of the correct customer group and X is enabled, i don't want them to access /wishlist, or customer/account, i want those pages to be redirected to the homepage.

What i've tried is to add redirects specific to store view X of type 302,

i.e. request path - wishlist, target path - ../, type 302

I've then tried reindexing and navigating to the page wishlist, only to find the redirect doesn't work. That route doesn't even hit Magento\UrlRewrite\Controller\Router match() ln 60.

how can i redirect pages such as this for a specific store view, and can someone explain why the Router isn't being hit?



  • Do you have fullpage cache enabled ? – Franck Garnier Mar 1 '17 at 12:13
  • I've tried with the cache enabled and disabled. The redirect works on some pages but not others so i'm not sure the cache is the issue. – Sophie Baxter Mar 1 '17 at 12:30
  • I'm starting to think it's the Magento\Framework\App\FrontController.php dispatch() matching a custom router before the url redirect router as it loops through the router list. How do I get it to match against the url redirect router before all others though? – Sophie Baxter Mar 1 '17 at 12:33
  • Indeed the router is sorted : Base Router → CMS Router → UrlRewrite Router → Default Router – Franck Garnier Mar 1 '17 at 13:56

You can add an observer to the controller_action_predispatch event in order to add your own logic of restriction.


<event name="controller_action_predispatch">
    <observer name="custom_restrict" instance="Vendor\Restriction\Observer\CustomRestrict" />


 * Implement some restriction
 * @param \Magento\Framework\Event\Observer $observer
 * @return void
public function execute(\Magento\Framework\Event\Observer $observer)
    /* @var $controller \Magento\Framework\App\Action\Action */
    $controller = $observer->getEvent()->getControllerAction();


Where $this->restrictor is your restriction class model with your logic.

But you may encounter problems if you use Varnish or other cache system.

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.