Routing: An Overview
URLs should be clean. Code should be simple. Trongate delivers both - no config files, no YAML, no Route::get() ceremonies.
Old-school PHP:
Trongate:
That’s it. No question marks. No cat-on-keyboard URLs. Just URLs that humans trust and Google rewards.
Three Types of Routing
Trongate offers the following three types of routing, all of which will be covered in this chapter:
| Type | What Happens | Ceremony Required |
|---|---|---|
| Homepage | Hit root → welcome module loads automatically | None |
| Automatic | /users/profile/88 → Users->profile(88) | None |
| Custom | You define the rule in one line of PHP | One line |
Routing vs URL Rewriting vs Redirecting
These three concepts often get mixed up. Let's settle it, once and for all. Here’s the definitive, no-BS breakdown:
At a glance:
- Rewriting – web server (Apache/Nginx)
- Routing – Trongate framework
- Redirecting – browser (after HTTP response)
1. Routing (with Trongate)
What it does: Tells Trongate which controller/method to run.
Where: config/custom_routing.php or via automatic URL routing
Address bar changes? No.
Example:
/blog/old-slug → Posts->show(123)
Think of it like this: Routing changes what loads, not the address bar.
2. URL Rewriting (Server)
What it does: Secretly funnels all requests to index.php so pretty URLs work.
Where: .htaccess (Apache) or Nginx config.
Address bar changes? No.
Example (Apache):
Think of it like this: Rewriting is a backstage pass that sneaks every URL into index.php.
3. Redirecting (HTTP)
What it does: Tells the browser “go somewhere else”.
Where: Server sends response → browser navigates to another URL.
Address bar changes? Yes.
Example:
/old-page → /new-page
Trongate helper example:
NOTE: is a helper function that's built into Trongate. Use it to perform an HTTP redirect.
Think of it like this: Redirecting says, “Wrong door, mate. Try next door.” User sees the new URL.
Quick Summary Table (Tattoo This)
| Routing | Rewriting | Redirecting | |
|---|---|---|---|
| Changes address bar? | No | No | Yes |
| Handled by | Trongate | Web server | Browser |
| File | custom_routing.php | .htaccess | header() |
Never forget:
- Routing = different content, same URL.
- Rewriting = sneak into
index.php. - Redirecting = new address, new page.
PS – You forgot already, didn’t you?