How to create routes in the codeigniter

// File: application/config/routes.php

// Default route
$route['default_controller'] = 'welcome';

// Custom route for specific URL
$route['products'] = 'catalog/products';

// Route with parameters
$route['product/(:num)'] = 'catalog/product_lookup/$1';

// Regular expression route
$route['blog/(:any)'] = 'blog/posts/$1';

Explanation:

  1. Default Route:
  2. $route['default_controller'] = 'welcome';
  3. Sets the default controller for the application. When no controller is specified in the URL, it directs to the 'welcome' controller by default.

  4. Custom Route for Specific URL:

  5. $route['products'] = 'catalog/products';
  6. Directs requests to the 'products' URL to the 'catalog' controller's 'products' method.

  7. Route with Parameters:

  8. $route['product/(:num)'] = 'catalog/product_lookup/$1';
  9. Matches URLs like 'product/{number}' and redirects them to the 'catalog' controller's 'product_lookup' method while passing the number as a parameter.

  10. Regular Expression Route:

  11. $route['blog/(:any)'] = 'blog/posts/$1';
  12. Matches URLs like 'blog/{any}' and routes them to the 'blog' controller's 'posts' method while passing the parameter 'any'. This '(:any)' segment in the route allows any characters in the URL to match this route. ```