I have custom controller outputting JSON format which works well for the below URL level;

** Works
base url/module/folder/action
//equates to Vendor\Module\Controller\Folder\Index.php

However I would like some somewhat deeper nested URL endpoints as per below but I get 404 on controllers deeper that one folder;

**Hit with 404
base url/module/folder/anotherfolder/action
//equates to Vendor\Module\Controller\Folder\Anotherfolder\Index.php

/* or even deeper */

**Hit with 404 - not tested
base url/module/folder/anotherfolder/deeperfolder/action
//equates to Vendor\Module\Controller\Folder\Anotherfolder\Deeperfolder\Index.php

I'm guessing Magento2 doesn't allow deep nested URL types or controllers ...

For me, this deeper nesting would be ideal to have a more manageable controller development & access since we have lost the ability to have multiple actions/endpoints in the one controller (Magento 1.*) (advise if not the case)

2 Answers 2


For this path


URL will be


As per as magento URL format is


frontenName is defined at routes.xml

ActionFolder locates at Controller folder which can multiple folders path but path will connect via (_) Undescore

Action is the php class.
  • ideally I would prefer URL without underscores (underscores changed to forward slashes) but this would need additional rewrites programmatically (and not manually created via admin panel etc)
    – BENN1TH
    Commented Sep 15, 2018 at 6:18

In Magento Catalog module has very nice and simple example by adding any product to compare.

Url Action Is :-

Your Layout is :-


Folder structure is :-


It's very simple, magento has many examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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