Two controller/actions, same URL

Hi there,

I’ve been having this problem serveral times, so now I’ve decided to make a workaround, but before I do so, and post a workaround, I would like to hear you opinion. There might be some way to do this.

Because I base a lot of my business on SEO, I often have to have two different controller actions with the same url. A real life example is a webshop with products and possibility to tag products. For each tag there is a page describing the tag and links to products in it. A tag’s url rule should be “’/<slug>’ => ‘tag/show’” and a product’s url should be “’/<slug>’ => ‘product/show’”. The problem is clear; I cant have both.

The temporary fix is something like:


'/<ProductSlug>' => 'product/show'

'/<tagSlug>' => 'tag/show'

And then in "product/show" forward to "tag/show" if no product was found for that url.

Have you ever had this problem? How did you solve it?

It’s possible to define custom UrlRule classes in the upcoming 1.1.8 version. It should solve your problem, you may already play around with it by getting the latest dev-version from the svn trunk.

You can read the docs for that feature here.

Looks really nice.

But still, I would have to create a special rule each time, and if I decide to change the rules, it’s not enough to correct in the config, I would have to rewrite the class also.

I’ve been thinking of a solution going along the lines of:

Try the first match, if the pages returns 404, try the next match. But I’m not sure how…

Maybe I could write a "depends" url rule class which takes an array of rules and a respective piece of php code (like bizRule in RBAC). This PHP code could be evaled and if true, use the respective URL… Might that be a solution?