Jump to content

redirect urls to module


Recommended Posts

Hello.

 

Example:

wwwdotexample.com/en/qwe --> goes to my custom module controller, everything is fine.

wwwdotexample.com/en/qwe/asd --> 404

wwwdotexample.com/en/qwe/zxc --> 404

wwwdotexample.com/en/qwe/.... --> 404

 

 

So my question is: what is the "proper" way in Prestashop to assign any "/qwe/(.*)" urls to that module?

 

I hope my explanation of what I'm looking for is simple and easy to understand.

 

Best regards.

Link to comment
Share on other sites

the 404 errors are correct since your url would point to a directory which does not exist. Correct way:

 

www.dotexample.com/en/qwe?param=asd

 

where param can be any url variable and asd its assigned value. you can fetch these values with

Tools::getValue

Link to comment
Share on other sites

Yea I know that the 404 errors are correct at this point and I'm not looking for how to pass parameters in the url. I'm looking for a way to achieve a specific behavior and I have my reasons for it (large part of it being that I have 6h left to make really old code work with presta, after that I'll have time to rewrite it).

Link to comment
Share on other sites

No worries. I wasn't very clear about it anyway. I forgot to click "Save" when I edited my 2nd post with more info and clarification that I need to add a rule to dispatcher.
So here is how I solved it:

 

public function install() {
    if (
            ...
            !$this->registerHook('moduleRoutes')
    ) {
        return false;
    }
    return true;
}

public function hookModuleRoutes() {
    return array('qwes' => array(
            'controller' => 'display',
            'params' => array(
                'fc' => 'module',
                'module' => 'qwe',
            ),
            'rule' => '{qwe}/{rewrite}',
            'keywords' => array(
                'qwe' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'qwe'),
                'rewrite' => array('regexp' => '(.*)')
            ),
        ),
    );
}

 

 

Edited by uldo (see edit history)
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...