octobercms/october · error · ValidationException

cms::lang.page.invalid_url

Error message

cms::lang.page.invalid_url

What it means

ValidationException thrown from `Page::beforeValidate()` when the page's `url` attribute fails `RouterHelper::validateUrl()`. CMS page URLs must start with a forward slash and contain only characters valid in a route pattern (with `{...}`/`:param` placeholders allowed). The rule fires on every page save/validate, before the standard 'required' rules settle.

Source

Thrown at modules/cms/classes/Page.php:75

     * data to the page object.
     */
    public $apiBag = [];

    /**
     * @var array rules to be applied to the data.
     */
    public $rules = [
        'title' => 'required',
        'url' => 'required',
    ];

    /**
     * beforeValidate applies custom validation rules
     */
    public function beforeValidate()
    {
        if (!RouterHelper::validateUrl($this->getAttribute('url'))) {
            throw new ValidationException(['url' => Lang::get('cms::lang.page.invalid_url')]);
        }
    }

    /**
     * getCodeClassParent returns name of a PHP class to us a parent for the PHP class
     * created for the object's PHP section.
     * @return mixed Returns the class name or null.
     */
    public function getCodeClassParent()
    {
        return PageCode::class;
    }

    /**
     * getLayoutOptions returns a list of layouts available in the theme.
     * This method is used by the form widget.
     * @return array Returns an array of strings.
     */

View on GitHub (pinned to b608633a7e)

Solutions

  1. Make the URL root-relative starting with '/', e.g. '/about-us'.
  2. Replace spaces and special characters with hyphens; move dynamic segments into proper parameters like '/blog/:slug'.
  3. If generating pages in code, normalize with a slug helper before assigning the url attribute.

Example fix

// before
$page->url = 'about us';

// after — root-relative, hyphenated, parameter syntax for dynamics
$page->url = '/about-us';
// or: $page->url = '/blog/:slug';
Defensive patterns

Strategy: validation

Validate before calling

use Cms\Classes\RouterHelper;

$url = $request->input('url');
if (!is_string($url) || !RouterHelper::validateUrl($url)) {
    throw new ValidationException(['url' => 'URL must start with / and contain only valid route characters.']);
}
$page->url = $url;
$page->save();

Try / catch

try {
    $page->save();
} catch (Winter\Storm\Exception\ValidationException $e) {
    // errors keyed by field: ['url' => ...] — map straight back to the form
    return back()->withErrors($e->getErrors())->withInput();
}

Prevention

When it happens

Trigger: Saving a page whose URL is 'about' (missing leading slash), contains spaces or accented/illegal characters, or uses malformed parameter syntax; creating pages programmatically or via importers that don't normalize URLs.

Common situations: Pages imported from another system with full URLs ('https://site.com/about') or relative paths; content editors pasting titles with spaces into the URL field; API-generated pages skipping normalization.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/d18b087e22e68973. Report an issue: GitHub.