Skip to content

Commit 0458c8a

Browse files
authored
(docs) Add redirects best practices and info on default version (#1166)
1 parent 76e2bae commit 0458c8a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

fern/products/docs/pages/navigation/products.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ products:
188188
```
189189
</CodeBlock>
190190

191+
<Markdown src="/snippets/default-version.mdx" />
192+
191193
</Step>
192194
<Step title="Indicate availability">
193195

fern/products/docs/pages/navigation/versions.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Version-specific `yml` files:
4444
</Step>
4545
<Step title="Add your version configuration">
4646

47-
Define a version in the top-level `docs.yml` by adding an item to the `versions` list and specifying the `display-name` and `path`.
47+
Define a version in the top-level `docs.yml` by adding an item to the `versions` list and specifying the `display-name` and `path`.
4848

4949
<CodeBlock title="docs.yml">
5050
```yaml
@@ -55,6 +55,9 @@ versions:
5555
path: ./versions/v2.yml
5656
```
5757
</CodeBlock>
58+
59+
<Markdown src="/snippets/default-version.mdx" />
60+
5861
</Step>
5962
<Step title="Indicate availability">
6063

fern/snippets/default-version.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Note title="Default versions">
2+
3+
Versions appear in the version dropdown in the order listed in `versions`. The first version in your `versions` list is your default version. This version uses unversioned paths like `/docs/getting-started`, while other versions use versioned paths like `/docs/getting-started/v2`.
4+
5+
Fern automatically handles version routing by [redirecting](/docs/seo/redirects) broken versioned links to the default version and managing canonical URLs.
6+
</Note>

fern/snippets/redirects.mdx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The `redirects` object allows you to redirect traffic from one path to another. You can redirect exact paths or use dynamic patterns with [`regex`](https://www.npmjs.com/package/path-to-regexp) parameters like `:slug` to handle bulk redirects. You can redirect to internal paths within your site or external URLs.
22

3-
If your docs are hosted on a subpath (like `buildwithfern.com/learn`), include the subpath in both the source and destination paths.
3+
If your docs are hosted on a subpath (like `buildwithfern.com/learn`), include the subpath in both the source and destination paths.
44

55

66
<CodeBlock title="docs.yml">
@@ -38,3 +38,40 @@ If your docs are hosted on a subpath (like `buildwithfern.com/learn`), include t
3838
<ParamField path="permanent" type="boolean" required={false}>
3939
Toggle between **permanent** and **temporary** redirects (default `false`). When true, the status code is 308. When false, the status code is 307.
4040
</ParamField>
41+
42+
### Best practices
43+
44+
For optimal site performance, only add redirects when necessary. Avoid using redirects for behavior that Fern already handles automatically, such as 404 handling and version routing.
45+
46+
<AccordionGroup>
47+
<Accordion title="404 handling">
48+
49+
Don't create redirects to send broken links to your homepage:
50+
51+
```yaml title="docs.yml"
52+
redirects:
53+
- source: /docs/event-notifications
54+
destination: / # Don't do this
55+
```
56+
57+
Instead, reach out to Fern to enable automatic homepage redirects, an internal setting that handles broken links without needing manual redirects.
58+
59+
</Accordion>
60+
<Accordion title="Versioning and redirects">
61+
62+
If you have [versions](/docs/configuration/versions) configured, your default version uses unversioned paths (`/docs/getting-started`), while other versions use versioned paths (`/docs/getting-started/v2`). Fern automatically handles version routing by redirecting broken versioned links to the default version and managing canonical URLs.
63+
64+
Avoid redirecting from unversioned to versioned URLs:
65+
66+
```yaml title="docs.yml"
67+
redirects:
68+
- source: /docs/event-notifications
69+
destination: /docs/event-notifications/v2 # Don't do this
70+
```
71+
72+
Manually overriding the default versioning behavior can lead to unexpected redirect patterns.
73+
74+
If you frequently need to redirect from the default version to another version, consider changing which version is set as default in your versions configuration.
75+
76+
</Accordion>
77+
</AccordionGroup>

0 commit comments

Comments
 (0)