octobercms/october · warning · October\Rain\Exception\ValidationException
Route prefix must start with a forward slash (/)
Error message
Route prefix must start with a forward slash (/)
What it means
SiteDefinition::beforeValidate() enforces the route prefix format for prefixed multisite sites: when is_prefixed is on, route_prefix must start with '/' and must not be exactly '/'. Any other value (missing slash, trailing-only slash, bare '/' or empty) throws a ValidationException on the route_prefix field.
Source
Thrown at modules/system/models/SiteDefinition.php:133
'is_enabled_edit' => true,
'group_id' => null,
'group' => null,
];
$site->syncOriginal();
return $site;
}
/**
* beforeValidate
*/
public function beforeValidate()
{
if ($this->is_custom_url && !Url::isValidUrl($this->app_url)) {
throw new ValidationException(['app_url' => __("Please specify a valid URL")]);
}
if ($this->is_prefixed && (substr($this->route_prefix, 0, 1) !== '/' || $this->route_prefix === '/')) {
throw new ValidationException(['route_prefix' => __("Route prefix must start with a forward slash (/)")]);
}
if ($this->is_host_restricted && !$this->isAllowHostsValid()) {
throw new ValidationException(['allow_hosts' => __("Please specify a valid hostname")]);
}
$this->fallback_locale = $this->getFallbackLocale($this->locale);
}
/**
* getFallbackLocale attempts to extract the fallback language from the locale.
* @return string
*/
protected function getFallbackLocale($locale)
{
if ($position = strpos($locale, '-')) {
$target = substr($locale, 0, $position);
$available = $this->getLocaleOptions();View on GitHub (pinned to b608633a7e)
Solutions
- Set the prefix with a leading slash and a non-empty segment: /en, /de
- Disable the 'prefixed' option if the site should not use a route prefix at all
- When saving programmatically, normalize before save: '/' . trim($prefix, '/') when non-empty
Example fix
# before route_prefix: "en" # after route_prefix: "/en"
Defensive patterns
Strategy: validation
Validate before calling
$prefix = trim((string) $site->route_prefix);
if ($prefix !== '' && $prefix !== '/') {
$site->route_prefix = '/' . trim($prefix, '/');
} Prevention
- Enter route prefixes with a leading slash and a non-empty segment (/en)
- Normalize config-provided prefixes before saving sites programmatically
- Remember '/' alone is invalid — it would match every route
When it happens
Trigger: Saving a site with is_prefixed enabled and route_prefix 'en', 'en/', '/', or an empty string.
Common situations: Typing the locale/prefix without the leading slash in the site form; assuming '/' alone is valid for the root; provisioning sites from config where the prefix lost its slash.
Related errors
- Please specify a valid URL
- cms::lang.page.invalid_url
- Cannot find the requested row group.
- Inspector container ${$containerHolder.data['inspector-conta
- Cannot switch to container: a container element is not found
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/4546f993103b876e.
Report an issue: GitHub.