urlManager rules for route aliases

Hi All,

In order to better SEOize my front-end web app, I wanted to create aliases for some of my routes that use dashes to separate words. For example, I have a route /mymodule/mycontroller/flyingmonkeyswithguitars. However, I want search engines to find this page based on key words in the action name. Therefore, I want my app to use and display the route as /mymodule/mycontroller/flying-monkeys-with-guitars. How would I go about creating a urlManager rule that basically strips dashes from the action name before mapping the route? Thanks in advance for any help!

Are you not using path format in urlmanager config? You can do:




'rules' => array(

   'this/is/an-example' => 'module/controller/action',

),



Check out guide about friendly url’s.

Thanks, Y!!. Yes, I am using urlFormat=>path, but I guess I was looking for something more dynamic. I could "hard code" each and every aliased route, but instead would rather create one rule that basically strips dashes from the action name and uses what is left as the mapped action ID. (So, /an-example maps to /anexample, and /heres-another-example maps to /heresanotherexample.) Is that possible with a rule? Thanks again.

No this is not possible within the rules array.

If you really need this you can create a parent controller, override missingAction() and then run the correct action (with removed dashed). I guess you use creatUrl() somewhere in your application, so in order to create the correct url for an action, I guess you have to override createUrlRule() of the url manager.

But unless you don’t have like hundred rules I would just put every rule into the config.

Thanks again for the reply. That makes sense. And you’re right, its probably just eaiser to write out each rule for this with a relatively small web app. If/when the app gets larger I’ll override my base Controller and CUrlManager.