How to change a part of the url in codeigniter?

by tressie.damore , in category: PHP Frameworks , 5 months ago

How to change a part of the url in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by deron , 5 months ago


In CodeIgniter, you can change a part of the URL by routing the request to a specific controller and method combination.

Here are the steps to follow:

  1. Open the application/config/routes.php file.
  2. Find the $route['default_controller'] parameter. It specifies the default route for your application. Change it according to your needs if required.
  3. Below the default route, you can define custom routes. Each route consists of two parts separated by an equal sign: the URL pattern and the corresponding controller and method.

For example, if you want to change to, you can add the following route:

$route['greetings'] = 'welcome';

Here, greetings is the new URL segment, and welcome is the controller that will handle the request.

You can also specify a specific method of the controller by adding it after the controller name, separated by a forward slash. For example:

$route['greetings'] = 'welcome/index';

  1. Save the routes.php file.

Now, when you access, CodeIgniter will route the request to the Welcome controller's index method.