Jump to content

Module friendly URL


Recommended Posts

Hi,

 

I am currently developing a new module for Prestashop and I would like it to have a nicer friendly url.

Right now, the most that I managed was to create a page in SEO & URLS, but still I don't like it.

 

The link to the page of the module is:

domain.com/flower-deliveries?city=Dalton&id_country=21&country=United+States

 

Instead of that I would like a link similar to the one below:

domain.com/flowe-deliveries/Dalton-21-United+States.html

 

Does anyone know how to achieve that?

 

Thank you in advance!

 

 

Link to comment
Share on other sites

You need to install your module into the moduleRoutes hook and then specify the friendly URLs you want. For example, my Image/Video Gallery module uses the following code to add /gallery/ and /gallery/image.html URLs:

    public function hookModuleRoutes($params)
    {
        $context = Context::getContext();

        if (isset($context->employee)) {
            return array();
        }

        return array(
            'module-gallerync-gallery' => array(
                'controller' => 'gallery',
                'rule' => 'gallery/{gallery}',
                'keywords' => array(
                    'gallery' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'gallery')
                ),
                'params' => array(
                    'fc' => 'module',
                    'module' => 'gallerync'
                ),
            ),
            'module-gallerync-image' => array(
                'controller' => 'image',
                'rule' => 'gallery/{gallery}/{image}.html',
                'keywords' => array(
                    'gallery' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'gallery'),
                    'image' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'image'),
                ),
                'params' => array(
                    'fc' => 'module',
                    'module' => 'gallerync'
                ),
            ),
        );
    }

Hopefully, you can adapt this to create your URL.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...