Jump to content

Has anyone tried modify Dispatcher::default_routes to customize URL?


JasonWang

Recommended Posts

I want to add some new page to display different newsletters and a list of them. And I also dont want to use parameters in the URL, like www.xxx.com/newsletter?id=1.

 

I prefer the way Prestashop do with its product and category. like www.xxx.com/newsletter/1/newsTitle.html

 

But in backoffice, the SEO penal only allow me to add static friendly url, like the 1st kind above.

I read some code about how Dispatcher and Controller work in Prestashop. It seems that I just need to add new route rules in Dispatcher->default_routes, and all problems solved. (I already created the newsletterController, and for the URL www.xxx.com/newsletter, it works fine.)

 

the code to add is like: 

 

'newsletter_rule' => array(
'controller' => 'newsletter',
'rule' => 'newsletter/{id}/{rewrite}',
'keywords' => array(
'id' => array('regexp' => '[0-9]+', 'param' => 'id_newsletter'),
'rewrite' => 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]*'),
),
),

is it correct?

Edited by JasonWang (see edit history)
Link to comment
Share on other sites

  • 5 months later...
  • 6 months later...
  • 3 months later...

using this hook "ModuleRoutes". I can set the new rule like this

 

public function hookModuleRoutes()
    {
        $routes = array();
        $routes['profile_rule'] = array(
            'controller' => 'profile',
            'rule' => '{profile_name}',
            'keywords' => array(
                'profile_name' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'profile_name'),
                'rewrite' =>        array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'),
                'meta_keywords' =>  array('regexp' => '[_a-zA-Z0-9-\pL]*'),
                'meta_title' =>     array('regexp' => '[_a-zA-Z0-9-\pL]*'),
            ),
            'params' => array(
                'fc' => 'module',
                'module' => 'demomodule'
            )
        );
       
        return $routes;
    }

 

so it display the url like

 

https://www.example.com/demoprofile

 

link is working but the other prestashop pages like my account and index page gone blank after header.

 

Is anyone got the solution of this issues?

Edited by dks295 (see edit history)
Link to comment
Share on other sites

  • 3 years later...

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