Url Format Rules, Redirect From Index.php...

Hello everyone! A noob question here

How do I redirect requests like index.php/cola to index.php/posts/find/cola ?

And how do I do that only if the cola controller doesn’t exist?

You need to create your own URL manager.

In the parseUrl() method you write the code to find out if the controller exists or not.

Creating your own URL manager is relatively easy.

Yes you definitely need to write your own URL rules. Use the URLManager in config file for that.

eg: ‘cola’ => ‘post/find’

I am guessing ‘cola’ is the id to pass. Here the controller will be ‘post’ and action will be ‘find’. ‘cola’ should be the argument.

Try it!

Hi! And thank you for responding!

I meant that cola could be replaced with any argument(post name for example)

and I can’t write a rule for each of them…

Like index.php/<post name here>

My main problem is that I need to distinguish controller names from post names and only try to find a post if controller with that name doesn’t exist.

I would appreciate any manual on writing the parse url method

Ujjwal, as far as I understand ‘cola’ => ‘post/find’ won’t work for any argument, only for ‘cola’. is that correct?

You mean you need to write url only when the controller name does not exist, right? which means out of two one has to be static, mentioning url rules for each one of them. My guess is since you have few controllers use static for them like index.php/controllername => ‘controllername/’ and by default for post redirect to your post/name/<postname>

I hope you understand what I am trying to say. If not, please read this details. http://stackoverflow.com/questions/10908931/controlling-url-in-yii-controller-action-id-to-id

This might help!

let me know.

And yes, ‘cola’ => ‘post/find’ works only for cola as it is static.