2

I have custom frontend controller, I added the URL Rewrite for this controller

I want to figure out the way, How I send requesting URL to 404 page based on some condition within the controller.

I don't want the noroute redirect solution because it change the URL. For example if you disable the product, URL remain same but it goes to 404 page and also I don't want to remove the URL Rewrite for this controller as well.

Any help, experience and knowledge sharing would be appreciated.

1 Answer 1

0

Not sure if it is valid according to best practices but following also works for me:

use Magento\Framework\Exception\NotFoundException; 

and

public function execute() { ... if (something) { throw new NotFoundException(__('Page Not Found')); } ... } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.