In rewriting an existing site, with many links out in the wild (via advertisements, press releases, etc.), I had to find a way to use hyphenated urls (in the position of controller, method or argument).

Checking SO and the CI boards showed various takes. I’ll go through each, and end with my approach.

1. Using a custome Route class to replace all hyphens with underscores (

2. Using hooks to do the same thing to REQUEST_URI (

3. Using htaccess (

So… All of the above are valid, and show some pretty cool ideas. However, I couldn’t realistically convert all hyphens to underscores, as occasionally I needed those hyphens, for example some articles were titled (and fetched) using alpha keys (e.g., articles/some-article).

I ended up using having all my controllers extend a custom controller, and used the _remap function, to test if the method exists before and after the replacement:

Again, this was in a custom controller, so is fairly DRY…

Then all my “normal” controllers extend PS_Controller (see my post on extending the native controller here)
Another approach, for a different set of circumstances. Hope it helps somebody.