Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Custom Routing
Automatic routing is brilliant 99% of the time. This page is for the 1% when you want to bend URLs to your will.
Here's how it works. Open: config/custom_routing.php
Add one line. Refresh. Done.
Basic Routes – “Pretend You’re Somewhere Else”
Want /login to secretly run users/login?
<?php
$routes = [
'login' => 'users/login'
];
define('CUSTOM_ROUTES', $routes);
Result: Address bar stays /login. User sees login form. You look clever.
Dynamic Routes? It's Wildcards Ahoy!
Need to catch IDs, slugs, or entire paths? Three wildcards. No more. No less.
| Wildcard | Matches | Use When |
|---|---|---|
(:num) | 123 | Numeric IDs |
(:any) | macbook-pro | Slugs, categories |
(:all) | docs/api/v2/whatever | Capturing everything after MUST BE LAST |
CRITICAL RULE:
If using (:all) it must be the final segment in your pattern.
Below is an example of a custom_routing.php file that demonstrates using wildcards to map dynamic URLs to specific controllers and methods.
<?php
$routes = [
'product/(:num)' => 'store/item/$1',
'laptops/(:any)' => 'store/item/$1',
'docs/(:all)' => 'help/$all', // Works
// 'blog/(:all)/edit' => 'broken forever' // Does NOT work
];
define('CUSTOM_ROUTES', $routes);