You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** If both files exist, `routing.yaml` takes precedence.
196
198
197
199
### Benefits
198
200
@@ -234,6 +236,190 @@ class Home
234
236
235
237
See `tests/unit/RouteScannerTest.php` for working examples of basic route definition, route groups with prefixes, filter composition, and multiple routes per method.
236
238
239
+
## URL Rewrites
240
+
241
+
URL rewrites provide transparent URL rewriting before route matching. Unlike HTTP redirects (301/302), rewrites are internal and invisible to the client—the browser URL stays the same while the application routes to a different path.
242
+
243
+
### Use Cases
244
+
245
+
- **Override Package Routes**: Applications can override default routes from packages (e.g., CMS homepage)
246
+
- **Legacy URL Support**: Support old URLs without creating duplicate routes
247
+
- **Clean URLs**: Map user-friendly URLs to internal route structures
248
+
- **Environment-Specific Routing**: Different rewrites for dev/staging/production
249
+
250
+
### Configuration
251
+
252
+
Add rewrites to `config/routing.yaml`:
253
+
254
+
```yaml
255
+
# config/routing.yaml
256
+
rewrites:
257
+
'/': '/home' # Root goes to custom homepage
258
+
'/index': '/home' # Legacy URL support
259
+
'/index.php': '/home' # Handle old PHP URLs
260
+
'/blog': '/posts' # URL aliasing
261
+
'/about-us': '/company/about' # Clean URL to internal structure
262
+
```
263
+
264
+
### How It Works
265
+
266
+
```
267
+
1. Client requests: http://example.com/
268
+
2. Router receives: /
269
+
3. Rewrite applied: / → /home
270
+
4. Route matching: Finds route for /home
271
+
5. Response sent to client
272
+
6. Browser still shows: http://example.com/
273
+
```
274
+
275
+
### Example: CMS Homepage Override
276
+
277
+
**Problem:** CMS defines `GET /` but you want a custom homepage.
278
+
279
+
**Solution:**
280
+
```yaml
281
+
# config/routing.yaml
282
+
rewrites:
283
+
'/': '/custom/landing' # Rewrite root to your controller
284
+
285
+
controller_paths:
286
+
- path: 'app/Controllers' # Your controllers first
0 commit comments