Search code examples
phpcodeigniterurl-rewriting

How to replace underscores in codeigniter url with dashes?


I would like to know the simplest solution to changing the underscores of my codeigniter urls to dashes, for seo reasons.

My controllers look like:

public function request_guide() {
...Load view etc...
}

So to browse to this page I would have to go to:

www.domain.com/request_guide

But I want to be more seo friendly and use dashes instead of underscores, like so:

www.domain.com/request-guide

I am under the impression that codeigniter functions require underscores (might be wrong).

In previous projects I have simply used mod_rewrite but I believe that these actions can be performed using routes.

What is the easiest way for me to rewrite the urls replacing the underscores with dashes???


Solution

  • The routes config found in

    config/routes.php
    

    is your friend here.

    A simple

    $route['request-guide'] = "request_guide" ;
    

    will do this for you.