If your module is using front controller then it generates URLs according to the below principle.
1 |
"module/{module}{/:controller}". |
For instance, the controller “ view ” of the module “ belvg_fаq ” will have the address:
1 |
"module/belvg_faq/view" |
All our modules use the prefix ‘ belvg_ ‘ by default, that is why when generating a controller the end user will see our company name in the browser address bar. Of course, this is quite pleasant for us but not quite good for our users. But in Prestashop there is a way to hide the original address of the controller with the help of the hook “ mоduleRоutes “.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public function hookModuleRoutes() { return array( 'module-belvg_faq-view' => array( //Prestashop will use this pattern to compare addresses: module-{module_name}-{controller_name} 'controller' => 'view', //module controller name 'rule' => 'faq/view', //the desired page URL 'keywords' => array(), 'params' => array( 'fc' => 'module', 'module' => 'belvg_faq', //module name ) ), ); } |
But let’s take a more complicated example with some parameters included.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public function hookModuleRoutes() { return array( 'module-belvg_faq-view' => array( 'controller' => 'view', 'rule' => 'view/{id}-{wanted_url}.html', //the desired page URL contains parameters 'keywords' => array( //in the Keywords section we describe every parameter 'id' => array('regexp' => '[0-9]+', 'param' => 'id_view'), 'wanted_url' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), 'params' => array( 'fc' => 'module', 'module' => 'belvg_faq', ) ), ); } |
This method lets you generate addresses with the following structure:
http://{your_site}/view/8-howtomakeorder.html
In addition, the controller Tools::getVаlue( ‘id_view’ ), returns 8.
Unfortunately, this method also has some drawbacks. If you decide to use {id_view} at the end of the address, for example:
http://{your_site}/view/howtomakeorder-8.html,
then Dispatcher::loadRoutes(), that is responsible for loading patterns, will load your custom rule before other rules, therefore the custom rule will have a higher priority than the rule for the product page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
'product_rule' => array( 'controller' => 'product', 'rule' => '{category:/}{id}-{rewrite}{-:ean13}.html', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_product'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'ean13' => array('regexp' => '[0-9\pL]*'), 'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), 'reference' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'manufacturer' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'supplier' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'price' => array('regexp' => '[0-9\.,]*'), 'tags' => array('regexp' => '[a-zA-Z0-9-\pL]*'), ), ), |
Therefore the customers will not see the product page but will be redirected to the module controller. That is why you should be careful when creating custom rules for module URLs: they should not interfere with the default rules.
Good luck on your work and with new modules :)
Check also: How To Change Header Logo in Prestashop 1.7
Dear Huma,
the issue is pretty complicated. Unfortunately, it’s not possible to provide a qualitative answer without getting into details.
Please, contact our support department in case you need an individual consideration of the matter: [email protected]
We’ll be happy to assist.
Kindly,
Iryna
I have tried it n number of times but it is not working.