| 1 |
--- |
| 2 |
title: Configure permalinks |
| 3 |
linkTitle: Permalinks |
| 4 |
description: Configure permalinks. |
| 5 |
categories: [] |
| 6 |
keywords: [] |
| 7 |
--- |
| 8 |
|
| 9 |
Use the `permalinks` configuration to define custom URL patterns for your pages. Hugo supports two forms: a map form for simple section-based patterns, and an array form that supports [page matchers](g) for more precise targeting. |
| 10 |
|
| 11 |
> [!NOTE] |
| 12 |
> The [`url`][] front matter field overrides any matching permalink pattern. |
| 13 |
|
| 14 |
## Map form |
| 15 |
|
| 16 |
Define URL patterns for each top-level [section](g), keyed by [page kind](g). For example, to configure URL patterns for the `articles` section: |
| 17 |
|
| 18 |
{{< code-toggle file=hugo >}} |
| 19 |
[permalinks.page] |
| 20 |
articles = '/blog/:year/:month/:slug/' |
| 21 |
[permalinks.section] |
| 22 |
articles = '/blog/' |
| 23 |
{{< /code-toggle >}} |
| 24 |
|
| 25 |
To configure permalinks per language, nest the `permalinks` key under the language key: |
| 26 |
|
| 27 |
{{< code-toggle file=hugo >}} |
| 28 |
[languages] |
| 29 |
[languages.de] |
| 30 |
label = 'Deutsch' |
| 31 |
locale = 'de-DE' |
| 32 |
weight = 1 |
| 33 |
[languages.de.permalinks] |
| 34 |
[languages.de.permalinks.page] |
| 35 |
articles = '/artikel/:year/:month/:slug/' |
| 36 |
[languages.de.permalinks.section] |
| 37 |
articles = '/artikel/' |
| 38 |
[languages.en] |
| 39 |
label = 'English' |
| 40 |
locale = 'en-US' |
| 41 |
weight = 2 |
| 42 |
[languages.en.permalinks] |
| 43 |
[languages.en.permalinks.page] |
| 44 |
articles = '/blog/:year/:month/:slug/' |
| 45 |
[languages.en.permalinks.section] |
| 46 |
articles = '/blog/' |
| 47 |
{{< /code-toggle >}} |
| 48 |
|
| 49 |
## Array form |
| 50 |
|
| 51 |
{{< new-in 0.161.0 />}} |
| 52 |
|
| 53 |
Define an array of permalink entries to apply different URL patterns to different subsets of pages. Each entry requires a `pattern` key. Hugo applies the first matching pattern. |
| 54 |
|
| 55 |
The optional `target` key accepts a [page matcher](g). If `target` is omitted, the pattern applies to all pages. |
| 56 |
|
| 57 |
{{% include "/_common/configuration/page-matcher.md" %}} |
| 58 |
|
| 59 |
For example, to apply language-specific URL patterns to the `articles` section page and its leaf pages separately: |
| 60 |
|
| 61 |
{{< code-toggle file=hugo >}} |
| 62 |
[[permalinks]] |
| 63 |
pattern = '/artikel/' |
| 64 |
[permalinks.target] |
| 65 |
path = '{/articles}' |
| 66 |
[permalinks.target.sites] |
| 67 |
[permalinks.target.sites.matrix] |
| 68 |
languages = ['de'] |
| 69 |
[[permalinks]] |
| 70 |
pattern = '/artikel/:year/:month/:slug/' |
| 71 |
[permalinks.target] |
| 72 |
path = '{/articles/**}' |
| 73 |
[permalinks.target.sites] |
| 74 |
[permalinks.target.sites.matrix] |
| 75 |
languages = ['de'] |
| 76 |
[[permalinks]] |
| 77 |
pattern = '/blog/' |
| 78 |
[permalinks.target] |
| 79 |
path = '{/articles}' |
| 80 |
[permalinks.target.sites] |
| 81 |
[permalinks.target.sites.matrix] |
| 82 |
languages = ['en'] |
| 83 |
[[permalinks]] |
| 84 |
pattern = '/blog/:year/:month/:slug/' |
| 85 |
[permalinks.target] |
| 86 |
path = '{/articles/**}' |
| 87 |
[permalinks.target.sites] |
| 88 |
[permalinks.target.sites.matrix] |
| 89 |
languages = ['en'] |
| 90 |
{{< /code-toggle >}} |
| 91 |
|
| 92 |
To define a fallback that matches any page not already matched by a preceding entry, place a pattern without a `target` key at the end: |
| 93 |
|
| 94 |
{{< code-toggle file=hugo >}} |
| 95 |
[[permalinks]] |
| 96 |
pattern = '/:section/:slug/' |
| 97 |
{{< /code-toggle >}} |
| 98 |
|
| 99 |
## Tokens |
| 100 |
|
| 101 |
Use these tokens when defining a URL pattern. |
| 102 |
|
| 103 |
{{% include "/_common/permalink-tokens.md" %}} |
| 104 |
|
| 105 |
[`url`]: /content-management/front-matter/#url |