Skip to content

Commit 877d7a7

Browse files
authored
Merge pull request #1138 from ExpressionEngine/7.dev
Pushing live config file route docs
2 parents b84035b + 483dd5a commit 877d7a7

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

docs/config/config-files.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ This file holds the duration of user session when 'remember me' checkbox is chec
6868

6969
This file lets you re-map URI requests to specific controller functions.
7070

71-
We generally recommend using [Template Routes](templates/routes.md) and not modify this file, unless you know you need to.
71+
This is different from Template Routes for templates.
72+
73+
- Controller routes (`routes.php`) map requests to controller methods.
74+
- Template Routes map requests to templates and are documented in [Template Routes](templates/routes.md).
75+
76+
If you want to define Template Routes in config, use `$config['routes']` (or `$config['routes:<site_id>']`) in `system/user/config/config.php` and keep [`enable_template_routes`](general/system-configuration-overrides.md#enable_template_routes) enabled.
7277

7378
#### Stop Words
7479

docs/general/system-configuration-overrides.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,8 @@ Example Usage:
13931393

13941394
This setting toggles whether or not Template Routes are used. If this is set to no, templates will not be accessible by their routes. When disabled the Template Route options will not appear in the Template Manager.
13951395

1396+
This setting applies to both Template Routes managed in the Control Panel and config-defined routes in `$config['routes']` / `$config['routes:<site_id>']`. If this is `n`, route matching is disabled.
1397+
13961398
| Value | Behavior |
13971399
| ----- | -------------------------------- |
13981400
| y | Enable Template Routes (default) |
@@ -1402,6 +1404,8 @@ Example Usage:
14021404

14031405
$config['enable_template_routes'] = 'y';
14041406

1407+
For config-defined route mappings, see [Template Routes](templates/routes.md#config-defined-routes).
1408+
14051409
## `enable_throttling`
14061410

14071411
If enabled, the system will throttle excessive web requests from potentially malicious users.

docs/templates/routes.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,47 @@ An issue arises if ExpressionEngine parses your routes in the above order when t
3939

4040
NOTE: **Important:** Template Routes overrides the default behavior of URLs, if you wish to use a Channel Entries Tag in your template you must manually provide segments for any parameters that are normally set in the URL. You must provide a segment for pagination, categories, and entry titles if you wish to use those in your Channel Entries Tag. Additionally, be careful when using `dynamic="yes"` with Template Routes, this can cause issues if your route does not have an appropriate segment set.
4141

42+
## Config-Defined Routes
43+
44+
In addition to managing routes in the Control Panel, you can define Template Routes directly in `system/user/config/config.php`.
45+
46+
Template Route matching requires [`enable_template_routes`](general/system-configuration-overrides.md#enable_template_routes) to be enabled. This setting defaults to `y`, so you only need to set it if it was previously disabled.
47+
48+
$config['enable_template_routes'] = 'y';
49+
50+
Define routes as an associative array where:
51+
52+
- the key is `template_group/template_name`
53+
- the value is the route pattern string
54+
55+
Example:
56+
57+
$config['routes'] = [
58+
'blog/index' => '/blarg',
59+
'blog/entry' => '/blarg/{url_title}',
60+
];
61+
62+
Regex rules use the same syntax as any other Template Route rule:
63+
64+
$config['routes'] = [
65+
'blog/article' => '/news/{slug:regex[([a-z0-9-]+)]}',
66+
'blog/year' => '/archive/{year:regex[((19|20)\d{2})]}',
67+
];
68+
69+
These routes use the same rule engine as routes created in the Template Manager.
70+
71+
NOTE: **Note:** When `$config['routes']` is present, the Template Route Manager is not available in the Control Panel. Manage those routes in config as the source of truth.
72+
73+
NOTE: **Advanced (MSM):** For site-specific route definitions, use `$config['routes:<site_id>']`. ExpressionEngine checks this key first and falls back to `$config['routes']` if no site-specific routes are defined.
74+
75+
$config['routes:1'] = [
76+
'blog/index' => '/site-one-blog',
77+
];
78+
79+
$config['routes'] = [
80+
'blog/index' => '/blog',
81+
];
82+
4283
### Template Route
4384

4485
This route determines the URLs that will match your template. The format is as follows:

0 commit comments

Comments
 (0)