SEO Friendly

I’ve a database with cities. And every city belongs to a municipality and a municipality belongs to a province. To create nice SEO friendly URLs I’ve saved a slug into my database. For example: noord-holland-wijdemeren-s-graveland. Where province is noord-holland, municipality wijdemeren and city s-graveland.

In the urlManager i created the rule:


'city/<id:\d+>/<province:[\w\-]+>/<municipality:[\w\-]+>/<city:[\w\-]+>' => 'city/view',

So i can go to http://domain.dev/city/1/noord-holland/wijdemeren/s-graveland/ and the id 1 will make sure i get the right city.

So far so good! But how i can create the url in my website using CHtml:link that goes to the URL just mentioned. Because the slug in the database is saved as ‘noord-holland-wijdemeren-s-graveland’ and not ‘noord-holland/wijdemeren/s-graveland’.

So my city record looks like this in the table:


id_city	country_id	province	municipality	city	sluge

1	1	Noord-Holland	Wijdemeren	's-Graveland	noord-holland-wijdemeren-s-graveland

Any ideas/hints/comments on my approach?

You are saying that you do not save province, municipality and city and at the same time your table contains province, municipality and city so finally do you save them separately in your table or not? If you do it is easy just pass them as parameters to chtml::link if you don’t you would have to do some more manipulation on the slug before you can render the link as you want it

thats not what i said. the problem is that i can’t build my url according to the information stored in the database. i stored the province name, municipality name and city name. those three together i used to build my sluge (SEO friendly name), also save in the database

So what goes wrong when i create an url:




$link = explode('-', $model->sluge);

$this->createUrl('city/view', array('id' => $model->id_city, 'province' => $link[0], 'municipality' => $link[1], 'city' => $link[2])



because the province and city i mentioned in the first post contains a dash (-)