How to use remap method in CodeIgniter

In this tutorial I will explain how to use remap method in CodeIgniter with simple example. CodeIgniter permits you to override which method in the controller gets called through the use of the _remap() method and allow you to define your own method routing rules.

Note : If your controller contains a method named _remap(), it will always get called regardless of what your URI contains.

For Example:

If you URI is like as below:

Here site is for controller name and about_us, contact_us are the methods in that controller. Now if you want to change your method name only from the URI (without actual change in the controller method), then you can use the _remap code to achieve this.

function _remap($method)
        // $method contains the method name from URI, that is second URI segment.
            case 'About-Us':
            case 'Contact-us':

Now you can change your URL as below: // calls about_me(); using _remap method // calls contact_us(); using _remap method

Hope this tutorial explained how to use _remap method in CodeIgniter.