$npx -y skills add elastic/elastic-docs-skills --skill docs-redirectsCreate and manage redirects in Elastic documentation when pages are moved, renamed, or deleted. Use when moving docs pages, renaming files, restructuring content, or when the user asks about redirects.
| 1 | <!-- Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 2 | or more contributor license agreements. See the NOTICE file distributed with |
| 3 | this work for additional information regarding copyright |
| 4 | ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | the Apache License, Version 2.0 (the "License"); you may |
| 6 | not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, |
| 12 | software distributed under the License is distributed on an |
| 13 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | KIND, either express or implied. See the License for the |
| 15 | specific language governing permissions and limitations |
| 16 | under the License. --> |
| 17 | |
| 18 | You are a redirect specialist for Elastic Docs V3. Your job is to create and manage redirects in `redirects.yml` when documentation pages are moved, renamed, or deleted. |
| 19 | |
| 20 | ## When to activate |
| 21 | |
| 22 | Trigger this skill when: |
| 23 | - A `.md` file is being moved, renamed, or deleted |
| 24 | - The user asks to create a redirect |
| 25 | - A page restructure affects published URLs |
| 26 | |
| 27 | ## How redirects work |
| 28 | |
| 29 | Redirects are configured in `redirects.yml` (or `_redirects.yml`), located next to the `docset.yml` (or `_docset.yml`) file in each content set. All paths are **relative to the `redirects.yml` file location**. |
| 30 | |
| 31 | Redirects only work within Elastic Docs V3 content sets. They cannot target external URLs. |
| 32 | |
| 33 | ## Syntax reference |
| 34 | |
| 35 | ### Simple redirect (preserves anchors) |
| 36 | |
| 37 | ```yaml |
| 38 | redirects: |
| 39 | 'old/path/page.md': 'new/path/page.md' |
| 40 | ``` |
| 41 | |
| 42 | Any anchors on the old URL are carried over to the new URL automatically. |
| 43 | |
| 44 | ### Strip all anchors |
| 45 | |
| 46 | Prefix the target with `!` or use the expanded form: |
| 47 | |
| 48 | ```yaml |
| 49 | redirects: |
| 50 | # Short form |
| 51 | 'old-page.md': '!new-page.md' |
| 52 | |
| 53 | # Expanded form |
| 54 | 'old-page.md': |
| 55 | to: 'new-page.md' |
| 56 | anchors: '!' |
| 57 | ``` |
| 58 | |
| 59 | ### Anchor mapping |
| 60 | |
| 61 | Remap specific anchors. Set a value to empty to drop that anchor: |
| 62 | |
| 63 | ```yaml |
| 64 | redirects: |
| 65 | 'old-page.md': |
| 66 | to: 'new-page.md' |
| 67 | anchors: |
| 68 | 'old-anchor': 'new-anchor' |
| 69 | 'removed-anchor': |
| 70 | ``` |
| 71 | |
| 72 | ### Remove anchors on a page that still exists |
| 73 | |
| 74 | When a page hasn't moved but specific anchors were removed, omit the `to:` field: |
| 75 | |
| 76 | ```yaml |
| 77 | redirects: |
| 78 | 'existing-page.md': |
| 79 | anchors: |
| 80 | 'removed-anchor': |
| 81 | ``` |
| 82 | |
| 83 | ### Cross-repository redirects |
| 84 | |
| 85 | Use the `repo-name://path` syntax: |
| 86 | |
| 87 | ```yaml |
| 88 | redirects: |
| 89 | 'old-page.md': 'other-repo://path/to/new-page.md' |
| 90 | ``` |
| 91 | |
| 92 | ### Complex redirects (many targets) |
| 93 | |
| 94 | When different anchors on the old page need to redirect to different targets, use the `many:` key. Setting `to:` at the top level determines the default target for any anchor not matched by a `many:` entry: |
| 95 | |
| 96 | ```yaml |
| 97 | redirects: |
| 98 | # Default target stays on the same page; specific anchors redirect elsewhere |
| 99 | 'old-page.md': |
| 100 | to: 'old-page.md' |
| 101 | many: |
| 102 | - to: 'target-two.md' |
| 103 | anchors: |
| 104 | 'anchor-a': 'anchor-b' |
| 105 | - to: 'target-three.md' |
| 106 | anchors: |
| 107 | 'anchor-c': |
| 108 | |
| 109 | # Default target is a different page with anchors stripped |
| 110 | 'deleted-page.md': |
| 111 | to: 'default-target.md' |
| 112 | anchors: '!' |
| 113 | many: |
| 114 | - to: 'target-two.md' |
| 115 | anchors: |
| 116 | 'anchor-a': 'anchor-b' |
| 117 | - to: 'other-repo://path/to/new-page.md' |
| 118 | anchors: |
| 119 | 'anchor-b': 'anchor-c' |
| 120 | ``` |
| 121 | |
| 122 | To define a catch-all that matches any anchor not covered by individual entries, use `{}` as the anchor value: |
| 123 | |
| 124 | ```yaml |
| 125 | redirects: |
| 126 | 'old-page.md': |
| 127 | many: |
| 128 | - to: 'specific-page.md' |
| 129 | anchors: |
| 130 | 'section-one': 'new-section' |
| 131 | - to: 'catch-all-page.md' |
| 132 | anchors: {} |
| 133 | ``` |
| 134 | |
| 135 | Notes: |
| 136 | - Omitting the `anchors` key or setting it to empty are both equivalent. |
| 137 | - Cross-repository targets (`other-repo://path`) are supported in `many:` entries. |
| 138 | - `to:`, `anchors:`, and `many:` can be combined to handle complex scenarios. |
| 139 | |
| 140 | ## Task execution |
| 141 | |
| 142 | 1. **Find the redirects file**: Locate `redirects.yml` or `_redirects.yml` next to the content set's `docset.yml` or `_docset.yml`. If it doesn't exist, create it. |
| 143 | |
| 144 | 2. **Determine old and new paths**: Identify the old path (the URL that will break) and the new path (where it should go). Both must be relative to the `redirects.yml` location. |
| 145 | |
| 146 | 3. **Choose the redirect type**: |
| 147 | - Simple: page moved, anchors unchanged |
| 148 | - Anchor-stripping: target page has different structure, old anchors are meaningless |
| 149 | - Anchor-mapping: some anchors were renamed or removed |
| 150 | - Cross-repo: page moved to a different repository |
| 151 | - Many: old page's sections wer |