Prestashop - Module, SEO & URL and parameters?

Show Details

Solution 1: [1]

you need to hook to moduleRoutes,

1) in your module install method:

if (!parent::install()           
    || !$this->registerHook('moduleRoutes')
    || !$this->registerHook('displayFooter'))
       return false;

2) creating corresponding hook

public function hookmoduleRoutes($params) {
    $routes = array();
    $routes['module-examplemodule-handler'] = array(
        'controller'=>'handler',
        'rule'=>'promo{/:code}',
        'keywords'=>array(
            'code'=>array(
                'regexp'=>'[\w]+',
                'param'=>'short_code'
            )
        ),
        'params'=>array(
            'fc'=>'module',
            'module'=>'examplemodule',
            'controller'=>'handler'
        )
    );

    return $routes;
}

module may have multi routes. the convention is module-[MODULE_NAME]-[MODULE_CONTROLLER_NAME]

array explanation:

controller - handler (modules/examplemodule/controllers/front/handler.php)

rule - curly braces are params.. you can get an idea from http://example.com/admin/index.php?controller=AdminMeta

keywords - here you configure your params (curly braces) defined in the rule.

usage example: http://example.com/promo/ADSGD

in controller 'handler':

$short_code = Tools::getValue('short_code');

tested on prestashop 1.6

reference: https://books.google.co.il/books?id=BsSiBQAAQBAJ&pg=PT134&lpg=PT134&dq=prestashop+module+Routes+hook&source=bl&ots=JCb_4oz6el&sig=JwoQfIsOnJ49VJ752fEb01ivMZ8&hl=en&sa=X&ei=vH0QVePiDoXPaNSxgrAP&ved=0CEIQ6AEwBA#v=onepage&q=prestashop%20module%20Routes%20hook&f=false



Credits

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Credit
Solution 1 salexch