Read More
Read More
Menu Close

    Custom URL in PrestaShop using moduleRoutes

    In this blog, we are going to learn how to show custom URL in PrestaShop using moduleRoutes hook. With the help of moduleRoutes hook we can also create custom rules for module controller.

    If module is using front controller then it generates URL’s according to the below rule


    For instance, the controller demo of the module demo_module will have the address:

    Custom URL in PrestaShop
    Before moduleRoutes Hook

    In above image you can see module name and controller are visible in url. But in Prestashop there is a way to hide the original address of the controller with the help of the hook mоduleRоutes.

    Prestashop will use this pattern to compare addresses: module-{module_name}-{controller_name}
    public function hookModuleRoutes() {
        return array(
            'module-demo_module-demo' => array( 
                'controller' => 'demo', //front controller name
                'rule' => 'mypage', //the desired page URL
                'keywords' => array(
                    'link_rewrite' => array(
                        'regexp' => '[_a-zA-Z0-9-\pL]*', 
                        'param' => 'link_rewrite'
                'params' => array(
                    'fc' => 'module',
                    'module' => 'demo_module', //module name
    Custom URL in PrestaShop
    After moduleRoutes Hook

    Using above method, we generate custom URL in PrestaShop using moduleRoutes hook as https://{your_site}/mypage

    Searching for an experienced
    Prestashop Company ?
    Read More

    When ever we open demo_module -> demo controller then the URL will be as https://{your_site}/mypage as shown in above image.

    Dispatcher::loadRoutes(), is responsible for loading patterns, will load your custom rule before other rules, therefore the custom rule will have a higher priority than the predefined PrestaShop rule.

    That’s all.

    If you are facing any issues or doubts in the above process, please feel free to contact us through the comment section.

    I would be happy to help.

    Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

    For any doubt contact us at [email protected].

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top