Routing
Quick Start: Adding a New Page
Create views/foo.php and /foo is a working URL. No route config needed.
If the page needs business logic, also create logic/foo_logic.php — it's auto-loaded by the view via getThemeFilePath. The two files together are a complete page.
views/notifications.php → /notifications works automatically
logic/notifications_logic.php → auto-loaded by the view (optional)Both files participate in the theme override chain, so themes can override them by placing their own versions in theme/{theme}/views/ or theme/{theme}/logic/.
This "view directory fallback" is the primary way simple pages are added. Most existing pages (/login, /booking, /notifications, etc.) work this way with no route entry.
When You DO Need a Route
Core's route table is includes/core_routes.php, which returns it; serve.php, the front controller, reads it on every request. The view fallback handles simple pages. You need an explicit route in the table when:
| Scenario | Example | Why fallback isn't enough |
|---|---|---|
| URL placeholders | /page/{slug} | URL captures a variable into $params for the view/logic |
| Feature-flag gating | 'check_setting' => 'events_active' | Page should 404 when feature is disabled |
| Permission gating | 'min_permission' => 10 | Page requires login/role check before rendering |
| Wildcard routes | /admin/* → adm/{path} | Maps a URL prefix to a different directory |
| Non-standard view path | /profile/devices/link → views/profile/devices_link | View file doesn't match the URL |
| Custom logic | Homepage with logged-in redirect | Requires a closure with complex branching |
.php), you don't need a route.Route Processing Order
Requests are processed in this order — first match wins:
0. Area words → A plugin area's word becomes its internal address (see Plugin areas and words)
1. Static routes → Assets (CSS, JS, images) served with cache headers
2. Plugin routes → Plugin-registered routes (checked before main routes)
3. Custom routes → PHP closures for complex logic
4. Dynamic routes → View routes from core's table and the plugins'
5. View fallback → Automatic: /foo → views/foo.php (theme-aware)
6. 404 → No match foundIf your route isn't matching, this order tells you what might be intercepting it first.
View Resolution Chain
When a view is loaded (whether from a route or the fallback), the system checks for theme and plugin copies:
theme/{theme}/views/foo.php → checked first (theme copy of a core view)
plugins/{plugin}/views/foo.php → checked second (the plugin's view)
views/foo.php → base system view
404 → none foundA file the plugin has is the plugin's. A theme's copy of it lives under the
theme's plugins/{plugin}/ folder, at
theme/{theme}/plugins/{plugin}/views/foo.php, and is checked before the
plugin's own. The theme's flat views/ folder holds copies of core views
only: a theme's homepage theme/{theme}/views/index.php never stands in for
a plugin's views/index.php, and a flat theme file that shares a plugin
view's name (theme/{theme}/views/cart.php) is never a page of its own:
the view fallback does not serve it at /cart, whether or not the plugin is
on.
This applies to logic files too (logic/foo_logic.php).
Dynamic content pages: pag_template
Most Pages render through views/page.php (and its themed overrides), which reads pag_title, pag_body, and pag_component_layout and produces markup. For Pages whose content depends on runtime state (e.g. a "thanks for signing up" page that formats the new user's name), set pag_template on the Page row:
pag_template = 'page_register_thanks'views/page.php then delegates to theme/{theme}/views/page_register_thanks.php. That template is a normal view with $page available and no framework magic — write whatever PHP you need inline.
A template's name starts with page_. Page::prepare() refuses a template that is not a page_... view in the theme, a plugin or the core views.
Route Configuration Reference
Core's routes are defined in includes/core_routes.php in three categories:
Static Routes
For assets only (CSS, JS, images, fonts). Never for PHP/dynamic content.
'static' => [
'/assets/*' => ['cache' => 43200],
'/plugins/{plugin}/assets/*' => ['cache' => 43200],
'/theme/{theme}/assets/*' => ['cache' => 43200],
'/favicon.ico' => ['cache' => 43200],
]Options: cache (seconds), exclude_from_cache (array of file extensions).
A versioned asset is kept for a year. A request under /assets/,
/plugins/{plugin}/assets/ or /theme/{theme}/assets/ that carries a v query
parameter is answered with Cache-Control: public, max-age=31536000, immutable;
without v it gets the route's cache time. A route with 'cache' => 0 and a
file type in exclude_from_cache are never given the long lifetime.
That makes one rule for every asset URL: *the v value must change when the
file does. The built-in helpers do it from the file's modification time
($this->asset_mtime() in a page class, filemtime() in a plugin view). A
hand-written fixed value such as ?v=1 pins the file in every browser for a
year.
A plugin's assets are served only while the plugin is active. A request
under /plugins/{plugin}/ for an inactive plugin is a 404. Checking costs that
request a database read, which no other static file pays.
/assets/plugin-styles.css is built, not a file in the tree. It is every
active plugin's declared stylesheets (styles in plugin.json) joined into
one file by PluginStyleBundle, and its v is a hash of those sheets' paths,
modification times and sizes. Built bundles live in
{site_root}/cache/plugin_styles/. Each sheet's part starts with a comment
naming its file. See the Plugin Developer Guide.
Dynamic Routes
View-based routes, with optional URL placeholders captured into $params.
'dynamic' => [
// Simple view — explicit file path
'/robots.txt' => ['view' => 'views/robots'],
// Slug-based content route — {slug} captured into $params['slug']
'/page/{slug}' => [
'view' => 'views/page',
'check_setting' => 'page_contents_active'
],
// Wildcard — maps URL prefix to directory
'/admin/*' => ['view' => 'adm/{path}'],
'/profile/*' => ['view' => 'views/profile/{path}'],
]URL placeholders ({slug}, {id}, etc.) are extracted into a $params array that's available in the view and any logic file it calls. Logic files load their own model objects from $params['slug'] (or whatever value is captured).
All dynamic route options:
| Option | Required | Description |
|---|---|---|
view | Yes | View file path, no .php. Supports {path}, {file}, {slug} placeholders |
handler | Yes | Alternative to view: a handler file (no .php) that fully serves the response itself (e.g. ICS downloads) — no view/theme resolution runs |
plugin | No | Plugin name that owns this route. View/handler and auto-loaded logic resolve from the plugin's directory; the route hard-404s while the plugin is inactive. See below |
check_setting | No | Setting name — route only serves if setting is truthy. Off, a route for one address answers 404; a wildcard route (/profile/*) steps aside so the view fallback can try the address |
static_cache | No | false — the response is never written to the static page cache and leaves no index entry (a search page, where every query string is its own page, or a link made for one recipient). A view can do the same with StaticPageCache::skipThisRequest() |
min_permission | No | Minimum permission level required (uses SessionControl::check_permission()). See the ladder below — note 0 requires login; omit the key for a truly public page. |
valid_page | No | Set false to exclude from page statistics (default: true) |
admin_page_check | No | false — a route inside an admin URL family that is public by its own declaration (/admin/server_manager/publish_theme, which other sites fetch with no session). Every other admin path needs its page's @joinery-admin level (below) |
view or handler.Admin pages
Before custom, dynamic and fallback routes, the router checks every admin
path (/admin/{name}, /admin/{plugin}/{name}, /plugins/{plugin}/admin/{name},
and a plugin's dynamic route inside /admin/, checked against its view) against
its page file's @joinery-admin header (AdminPageAccess): signed out, the sign-in
page; below the level, a 401. A page without a header needs 10. See
Permissions.
Plugin-delegated routes
Core hands one of its own addresses to a plugin with the plugin option when the address is fixed outside the site: something another site, a mail program, a payment provider or a printed code holds. The view (or handler) and auto-loaded logic resolve from the plugin's directory.
'/services/authorize' => ['view' => 'views/services/authorize', 'plugin' => 'server_manager'],
'/mail/config-v1.1.xml' => ['view' => 'views/autoconfig', 'plugin' => 'mail_apps'],/pricing is core's own page; the plugin that sells tiers supplies its offers (see Subscription Tiers). Every plugin page is routed by its plugin, at its areas (Plugin areas and words).
Two guarantees:
- Inactive plugin → hard 404. A plugin-delegated route is exclusively owned by its plugin. When the plugin is inactive or absent, the URL 404s outright — it never falls through to a theme or base view of the same name.
- The plugin gate runs before
check_setting. The gating setting row is seeded at plugin activation, so on a never-activated install it does not exist; checking the plugin first is what keeps that case a 404 instead of a silent fall-through.
serve.php, at an area. Plugin pages under the plugin's own namespace (/{plugin}/..., /profile/{plugin}/..., /admin/{plugin}/...; see Plugin Developer Guide) need no route entry — they auto-discover.A view a route serves has one address. When a route (core's or a plugin's) names a plugin view, that view answers only at the route's address: plugins/forum/views/topic.php answers at /forum/t/{id}, and /forum/topic is a 404. Auto-discovery never serves it a second time without the route's gate and options.
A plugin's own serve.php routes are held to its namespace: dynamic and custom routes outside /{plugin}, /profile/{plugin} and /admin/{plugin} are dropped with a logged warning, and static routes are never served (core's static routes are matched before plugin routes join the table).
A handler route finds its file the way a view route does: in the plugin its plugin option names, or else the plugin its address names (/office_editor/wopi/... → plugins/office_editor/).
Plugin areas and words
A plugin can divide its pages into areas, each answering at a word: the store's cart area at /cart/..., its member account area at /profile/billing/.... The plugin's plugin.json names each area's word and an optional fallback word (see Plugin Developer Guide); the Plugins page shows where each answers. Sites do not change words.
- Internal address. Every area page has
/{plugin}/{area}/{rest}(profile scope:/profile/{plugin}/{area}/{rest}), and the plugin'sserve.phpdeclares an explicit route there. Auto-discovery never finds an area page by its word. - Public address. Before any route is matched, after the page cache is read, the router looks at the first segment (or the one after
/profile/): 1. an area's word becomes the internal address, and matching goes on from there; 2. the internal address of an area that has a word forwards to/{word}/{rest}, query string kept. A forward is a 301 for GET and HEAD and a 308 for any other method, so a form or webhook posting to it keeps its method and body. It carriesCache-Control: no-store, because the area's word can change when a plugin update changes its manifest. The rest of the path is percent-encoded again, segment by segment.
REQUEST_URI see the address as requested, so a cached page and a redirect row are both keyed by the public address. RouteHelper::getAreaRewrite() names the rewrite; in match-only mode a forward is the result type area_redirect.
- One holder per word. A word belongs to one area of one plugin, or to core, never both.
AddressSpace::holder($scope, $segment)is the only thing that decides: core holds every first segment of its route table, its views (views/{word}.php,views/{word}/), every top-level entry ofpublic_html, the reserved plugin names and the words core keeps (search,help,account,members,support,status,feed,tag,about,contact,terms,privacy); every installed plugin's name is held; and so is every word an area holds. Every plugin folder on disk counts as a name too. Profile scope is its own space: core's/profile/{word}routes andviews/profile/{word}.php. - Who got which word is stored in
paw_plugin_area_words(PluginAreaWord), so an area keeps the word it got and a plugin activated later never takes it. An area takes itswordif free, else itsfallbackif free, else answers at its internal address; it keeps whichever it got while its manifest still names it, and takes another at the next sync once the manifest stops naming it. With the table missing (an upgrade between its file swap and its schema step), every area answers at its internal address and nothing throws. - A word core later answers stays the area's: core's new page is not reachable there. Sync, the upgrade (before the swap) and the top of the Plugins page name each such word.
Permission levels and the min_permission => 0 gotcha
The integer passed to min_permission is matched against the session's permission level:
| Level | Who |
|---|---|
0 | Any logged-in user (no rank requirement) |
1–4 | Member tiers |
5 / 7 / 9 | Admin tiers (5 = basic admin) |
10 | Superadmin / full system admin |
0 is not "public":'min_permission' => 0'= "must be logged in, any rank." The router gates onisset($config['min_permission']), andissetis true even when the value is0.check_permission()then redirects any not-logged-in visitor to/loginbefore it ever compares the level — so a0floor still forces a login.'min_permission' => 5'= "logged in and admin."- A truly public page omits the key entirely. With no
min_permission,issetis false and no check runs.
0 as "open" you get the safe failure — the page demands a login rather than
exposing itself — but it is still wrong. Use 0 for "any member," omit the key for "anyone."Custom Routes
PHP closures for complex logic. Return true if handled, false to continue to next route.
A handler that returns true and writes nothing is answered with a 500 and a ROUTING ERROR line in the error log, since a page that renders nothing is a bug nobody sees. An empty body the handler means is served: a redirect, a status it set itself (304, 204, 416), a Content-Length it declared (a zero-byte file is 200 with Content-Length: 0), or an answer to HEAD. What a handler writes is buffered; one that streams a file body leaves those buffers first, as File::serve_from_path() does, so the download never sits in memory.
'custom' => [
'/' => function($params, $settings, $session, $template_directory) {
// Homepage with logged-in redirect logic
return true;
},
]Common Patterns
The site root
/ is a custom route driven by two settings. alternate_homepage (factory /welcome) is where a visitor who is not signed in lands; alternate_loggedin_homepage (factory /profile) is where a member lands, and falls back to the public one when blank. A value of /welcome renders the welcome page at the root: views/index.php through the theme chain, so the built-in front door (the site's name, a line saying it is private, a Sign in button, and a register link only where register_active is on) or the active theme's own homepage. A plugin's page (the blog's listing at /blog, say) or /page/{slug} renders that content at the root; a plugin page that is switched off (its plugin inactive, or its route's check_setting off) renders the welcome page instead. Any other path is a 302 to it. The homepage choices the settings page offers beyond the core ones come from plugins, as SiteLinkRegistry links in the homepage role. Both blank renders views/index.php too. A signed-in member who reaches /login is sent to the signed-in homepage.Simple public page
views/notifications.php → /notifications
logic/notifications_logic.php → auto-loaded (optional)
No route needed.Slug-based content page
// In includes/core_routes.php, dynamic routes:
'/video/{slug}' => [
'view' => 'views/video',
'check_setting' => 'videos_active'
],
The view at views/video.php calls video_logic(array_merge($_GET, $_POST, $params ?? [])), and the logic file loads the Video by $input['slug']. A plugin's slug pages are routed the same way in its own serve.php, at an area's internal address (/store/products/{slug}).Admin page
Admin files live in/adm/, not /admin/. The wildcard route handles mapping:
'/admin/*' => ['view' => 'adm/{path}']
So /admin/admin_users loads adm/admin_users.php. Plugin admin pages auto-discover at /plugins/{plugin}/admin/*.Flat /ajax/* namespace (external webhooks + retained endpoints)
'/ajax/*' => ['view' => 'ajax/{file}']
This route survives for external webhooks — the store's Stripe/PayPal
handlers (plugins/store/ajax/) and the mailbox inbound-email webhook
(plugins/mailbox/ajax/inbound_email_webhook.php) — and for a small set of
retained page endpoints that predate the API surface. The one browser-facing
holdover is the entity-photo manager (ajax/entity_photos_ajax, driven by
PhotoHelper's upload/reorder/delete UI); it is documented in
Photo System.All new browser-facing endpoints are /api/v1 actions (_logic_descriptor()
opt-in, browser-session credential — see API). Do not
add new /ajax/ endpoints.
Permission-protected route
'/tests/*' => ['view' => 'tests/{path}', 'min_permission' => 10],
Redirects to login if not authenticated, shows 403 if insufficient permission.URL Rules
- Never use
.phpextensions in URLs or links. The routing system strips them. - Wrong:<a href="/admin/admin_users.php?id=1">- Right:<a href="/admin/admin_users?id=1"> - Query parameters (
?key=value) pass through routing unchanged and are available in$_GET. - A malformed path is refused at the door.
RouteHelper::processRoutes()runs the decoded request path throughRouteHelper::validatePath()before any route is matched or any file is looked up: a..segment, a backslash, a NUL byte or an encoded traversal at any decoding depth answers a plain 404. Apache decodes the URL once and PHP decodes__routeagain, so%252e%252earrives as.., past Apache's own dot-segment removal; the door is where that is caught. Every later name check (PathHelper::getThemeFilePath(), the static handler's ownvalidatePath()call) only ever catches programmer error.
The __route parameter
The Apache rewrite sends every request through the front controller as
serve.php?__route=<path>, so $_GET['__route'] is set on every request. It is
routing metadata, not page input — the route value is passed to dispatch as
$request_path. RouteHelper::processRoutes() therefore unsets
__route from $_GET / $_POST / $_REQUEST at dispatch entry, so page logic
never sees it.
This matters because logic functions receive array_merge($_GET, $_POST): if
__route leaked through, $input would be non-empty on every request and
if($input)-style submission guards would misfire (the bug fixed in
specs/implemented/admin_logic_get_submission_guard_fix.md). Don't reintroduce a
read of $_GET['__route'] in page code — use $request_path (or
$_SERVER['REQUEST_URI']) instead.
Static Page Cache
Anonymous GET requests are served from a static HTML cache stored in cache/static_pages/.
The cache is managed by includes/StaticPageCache.php and checked inside RouteHelper::processRoutes().
How it works:
- On a cache miss, PHP renders the page normally and the output is written to a
.htmlfile. - On a cache hit, the file is served directly with
readfile()— PHP does almost no work. The request starts its session and reads no setting, so it opens no database connection. - 1% of cache hits are randomly invalidated so pages stay fresh without a TTL.
- Pages that cannot be cached (login-required, POST responses, error pages) are marked
nostaticin the index and skipped on future checks. - Some paths are never cached nor served from the cache, whatever the index holds
(
StaticPageCache::isExcludedPath()): the sign-in and password-reset steps, the cart and checkout, file downloads, and/copy-key, which shows what this machine's agent is waiting for.
{site_root}/cache/static_pages/
index.json— maps URL keys to{status, url, time, extension}entriesindex.html— cached homepageabout_us.html— cached/about-us, etc.
specs/static_cache_diagnostics.md is
implemented):
- HTTP header
X-Cache: HIT— present on every cache hit - HTTP header
X-Cache-Created: <ISO 8601>— when the cached file was written - HTTP header
X-Cache-Age: <seconds>— age of the cached file - HTML source comment
<!-- Cached: / | Created: 2026-05-03T01:29:07+00:00 -->
/admin/admin_static_cache) and click "Clear All Cache". Automatic
invalidation covers the common cases (see below), so manual clearing should rarely be needed.Automatic invalidation:
alternate_homepageoralternate_loggedin_homepagesettings saved →/invalidatedactive_themesetting saved → entire cache flushed- An upgrade (
utils/upgrade.php) or a restore (reconcile_site.sh) → every saved page deleted;index.json, which holds whether the cache is on and which URLs arenostatic, is kept, and an entry whose page is gone is dropped the next time it is asked for - A forum change → that topic's pages, its category,
/forumand/sitemap(see the forum plugin's docs)
StaticPageCache::invalidateUrl($url, $params) removes one exact URL.
StaticPageCache::invalidatePath($path, $with_children = false) removes every cached copy of a
path whatever its query string (?page=2 goes with the first page), and with $with_children
everything under it too. Content whose change reaches every page of it — a thread, a list —
uses invalidatePath().Debugging
Add ?debug_routes=1 to any URL to see route matching details in HTML comments. Requires superadmin login.
Check error logs for route-related issues:
grep -i "route" /var/www/html/joinerytest/logs/error.log | tail -20
