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???
What you could do is create a custom hook (PST... you need basic CodeIgniter skills): for more information regarding CodeIgniter Hooks - Extending the Framework Core
I named the file customhooks.php.
Then add this to the hooks.php file in application/config:
You will need to edit your application/config/config.php file to enable hooks
EXTRA:
so that when you use $this->uri->uri_string() it stays hyphenated do the following Creating Core System Classes
Code Ignitor 3 has this in built:
$route['translate_uri_dashes'] = FALSE;
Just change to
TRUE
and you can use either_
or-
.Documentation
You can use this _remap() method to handle such behavior. Place this method in your controllers or create a core controller and place it in.
Open application/config/routes.php and change
That is it you need to do.
Now when you access www.domain.com/request-guide, it will instantiate request_guide controller.
It will work with all controllers with name containing _ (underscore).
The routes config found in
is your friend here.
A simple
will do this for you.