Redirects
Diplodoc allows you to configure redirects within a project:
- in static documentation — via page headers;
- in the cloud version — via the redirects.yaml file.
Redirects in static documentation
Warning
The proposed solution is temporary. In the future, redirects via redirects.yaml will be supported for static documentation, similar to the cloud version.
To configure a redirect, add meta tags to the beginning of the source page:
---
metadata:
- name: redirect
http-equiv: refresh
content: '0; url=<path_to_target_page>'
---
Field descriptions:
name: redirect— the name of the meta tag to indicate a redirect.http-equiv: refresh— page refresh by the browser.content: '0; url=<path_to_target_page>'— an attribute with parameters:0— delay in seconds before the redirect.0means an immediate redirect.url=<path_to_target_page>— the URL of the redirect target page.
In the url field, you can specify:
- An absolute path — the full URL of the page to which the redirect should be made.
- A relative path — the path from the source page or the root of the current project. For example,
../folder/pageor/root-folder/page.
To prevent the source page from appearing in the table of contents, hide it in the toc.yaml file:
- href: <path_to_source_page>.md
hidden: true
Limitations
- Anchor links are not preserved.
- The source file cannot be deleted from the project.
Example of an external redirect
Redirect from https://diplodoc.com/docs/ru/page-constructor/old-spec/ to https://preview.gravity-ui.com/page-constructor/.
-
File
/ru/page-constructor/old-spec/index.md:--- metadata: - name: redirect http-equiv: refresh content: '0; url=https://preview.gravity-ui.com/page-constructor/' --- -
File
/ru/toc.yaml:- href: page-constructor/old-spec/index.md hidden: true
Example of an internal project
Redirect from the page ru/settings/old-page.html to the page ru/settings/new-folder/new-page.html.
-
File
ru/settings/old-page.md:--- metadata: - name: redirect http-equiv: refresh content: '0; url=./new-folder/new-page.html' --- -
File
ru/toc.yaml:- href: settings/old-page.md hidden: true
Redirects in the cloud version
Redirects in the cloud version can be described in the redirects.yaml file, which must be located at the same level as the configuration file .yfm.
File structure
The redirects.yaml file consists of:
- language sections that contain redirects for individual documentation languages;
- the
commonsection with redirects for all documentation languages.
Redirects cannot be specified outside a section.
Warning
Redirects are checked in the following order:
- The section of redirects for individual documentation languages.
- The
commonsection.
Within sections, redirects are checked in the order they appear: from top to bottom.
Configuration specifics
-
Redirects are configured only within the documentation project.
-
Anchor links are not supported.
-
In the
commonsection, paths are specified relative to the project root. In language sections, paths are specified relative to the language folders without including them directly in the path. For directories, a/symbol is added at the end. Specifying the.mdextension is not required. Example file. -
Regular expressions can be used.
Code example
- from: /concepts/referral-(.*) to: /index
Example redirects.yaml
# Секция редиректов для отдельных языков документации
ru:
- from: /entry1
to: /folder1/entry1
en:
- from: /entry2
to: /folder2/entry2
# Секция common
common:
- from: /entry3
to: /folder3/entry3
Examples for files
|
Redirect |
Example |
|
The file was renamed |
|
|
The file was moved to a directory |
|
|
The file was moved to a parent directory and renamed |
|
|
The file was moved to a subdirectory and renamed |
|
|
The file was moved from a directory to the root |
|
|
All files were moved from a directory to the root |
|
Examples for directories
|
Redirect |
Example |
|
The directory was renamed |
|
|
All subdirectories were renamed |
|