Get Free Audit

How to Generate a Custom URL in PrestaShop

Jun 1, 2015

7612 Alex Simonchik

How to Generate a Custom URL in PrestaShop

If your module is using front controller then it generates URLs according to the below principle.


For instance, the controller “ view ” of the module “ belvg_fаq ” will have the address:


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 “.


But let’s take a more complicated example with some parameters included.

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


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:


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

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

2 Comments

  1. 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

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *