{"record":{"id":"d18b087e22e68973","repo":"octobercms/october","slug":"cms-lang-page-invalid-url","errorCode":null,"errorMessage":"cms::lang.page.invalid_url","messagePattern":"cms::lang\\.page\\.invalid_url","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/Page.php","lineNumber":75,"sourceCode":"     * data to the page object.\n     */\n    public $apiBag = [];\n\n    /**\n     * @var array rules to be applied to the data.\n     */\n    public $rules = [\n        'title' => 'required',\n        'url' => 'required',\n    ];\n\n    /**\n     * beforeValidate applies custom validation rules\n     */\n    public function beforeValidate()\n    {\n        if (!RouterHelper::validateUrl($this->getAttribute('url'))) {\n            throw new ValidationException(['url' => Lang::get('cms::lang.page.invalid_url')]);\n        }\n    }\n\n    /**\n     * getCodeClassParent returns name of a PHP class to us a parent for the PHP class\n     * created for the object's PHP section.\n     * @return mixed Returns the class name or null.\n     */\n    public function getCodeClassParent()\n    {\n        return PageCode::class;\n    }\n\n    /**\n     * getLayoutOptions returns a list of layouts available in the theme.\n     * This method is used by the form widget.\n     * @return array Returns an array of strings.\n     */","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/Page.php#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the URL root-relative starting with '/', e.g. '/about-us'.","Replace spaces and special characters with hyphens; move dynamic segments into proper parameters like '/blog/:slug'.","If generating pages in code, normalize with a slug helper before assigning the url attribute."],"exampleFix":"// before\n$page->url = 'about us';\n\n// after — root-relative, hyphenated, parameter syntax for dynamics\n$page->url = '/about-us';\n// or: $page->url = '/blog/:slug';","handlingStrategy":"validation","validationCode":"use Cms\\Classes\\RouterHelper;\n\n$url = $request->input('url');\nif (!is_string($url) || !RouterHelper::validateUrl($url)) {\n    throw new ValidationException(['url' => 'URL must start with / and contain only valid route characters.']);\n}\n$page->url = $url;\n$page->save();","typeGuard":null,"tryCatchPattern":"try {\n    $page->save();\n} catch (Winter\\Storm\\Exception\\ValidationException $e) {\n    // errors keyed by field: ['url' => ...] — map straight back to the form\n    return back()->withErrors($e->getErrors())->withInput();\n}","preventionTips":["Always build CMS URLs as root-relative strings starting with '/'.","Slugify titles before using them as URLs ( Winter\\Storm\\Support\\Str::slug ).","When importing pages, normalize: trim, prepend missing '/', replace spaces with '-'."],"tags":["validation","routing","url","cms-page"],"backgroundTag":"invalid-url-format","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}