Jump to content

URL link for custom module


Recommended Posts

Hi all,

 

I am currently developing a custom module.

What I want is to have a nice URL, because right now it looks like this:

domain.com/flower-deliveries?city=Hamburg&id_country=1&country=Germany

I already added a new page to link to the custom module, the page name is flower-deliveries, but still I have the parameters that I have to "hide".

Instead, of that link above I would like a URL like this:

domain.com/flower-deliveries-Hamburg-Germany.html

Can it be done? If yes, how? I've tried with .htaccess, like this. but with no luck..

RewriteRule ^flower-deliveries-([^-]*)-([^-]*)-([^-]*)\.html$ /flower-deliveries?city=$1&id_country=$2&country=$3 [L]
Edited by rosuandreimihai (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hi again,

 

I tried 2 methods, but none of them worked..

The first one, was to add a hookModuleRoutes in my controller, just like below:

public function hookModuleRoutes($params)
    {
        return array(
            'module-vpages-dpage' => array(
                'controller' => 'dpage',
                'rule' => 'flower-deliveries{/:id_country}{/:country}{/:city}',
                'keywords' => array(
                    'id_country' => array('regexp' => '[_a-zA-Z0-9_-]+', 'param' => 'id_country'),
                    'city' => array('regexp' => '[\w]+', 'param' => 'city'),
                    'country' => array('regexp' => '[\w]+', 'param' => 'country')
                ),
                'params' => array(
                    'fc' => 'module',
                    'module' => 'vpages',
                    'controller' => 'dpage'
                )
            )
        );      
    }

And then, in the controllers install:

$this->registerHook('moduleRoutes');

That didn't worked, so I tried to override the Dispatcher class, by adding a custom module route:

        'module-vpages-dpage' => array(
            'controller' => 'dpage',
            'rule' => 'flower-deliveries{/:setCountry}{/:id_country}{/:country}{/:city}',
            'keywords' => array(
                'setCountry' => array('regexp' => '[0-9]+', 'param' => 'setCountry'),
                'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
                'city' => array('regexp' => '[\w]+', 'param' => 'city'),
                'country' => array('regexp' => '[\w]+', 'param' => 'country'),
            ),
            'params' => array(
                'fc' => 'module',
                'module' => 'vpages',
                'controller' => 'dpage'
            )
        ),

When using that custom rule, the link http://europeanflora.com/flower-deliveries?module_action=list&id_country=44&country=Argentina&setCountry=44 was tranformed in http://europeanflora.com/flower-deliveries?module_action=list and it didn't worked and was redirecting me to the first page.

Could some one tell me what am I doing wrong?

 

I've spent hours of reading how it should be done and it should be just like the ones above..

 

Thank you!

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