Create url rewrite based on database values

I currently have the following rule:




This gives me URL like this: /mysite/view/14197.html

On the page I have some values output from the database, I want to include some of these values in my URL rewrite so I get URL like this:


($id - $bedrooms - bedroom - $type - $location)

How can I do this?

Can someone please help me with this? Thanks :)

'rules' => array(

        'view/<id:\d+>-<bedrooms:\d+>-bedroom-<type:\w+>-<location:\w+>' => 'search/view',


You can also do:

'rules' => array(

        'view/<id:\d+>-<seo:.+>' => 'search/view',


So with the last rule you can add any value, this would work:


Is that what you’re looking for?

That looks good to me, I will test it out tomorrow. Thanks!

What I’m actually trying to do is make it generate the URLs in the format I posted above. The only field that is matched in the database is the ID field, the rest will just be there for SEO purposes.

EDIT: It’s OK - I think I’ve figured it out. Thanks :)

Just having a slight problem - when I’m matching against values that have spaces it doesn’t seem to work.

For example: <location:\w+> sometimes contains two words, and the rewrite seperates the two words with a + symbol.

What do I need to do to make this work?

EDIT: I noticed underscore works - is it possible to make it generate underscore rather than plus symbol?

I managed to figure this out. I just did <location:> in the rule and ‘location’=>str_replace(" ", “_”, $model->location) in the view.

This works, but I’m not entirely convinced it’s the correct way of doing it.