Skip to content

Commit 72e9984

Browse files
committed
add redirects best practices and info on default version
1 parent e83b074 commit 72e9984

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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 appears at unversioned paths like `/docs/getting-started`, while other versions use versioned paths like `/docs/getting-started/v2`. Fern automatically handles version routing by [redirecting](/docs/seo/redirects) broken versioned links to the default version and managing canonical URLs.
4+
</Note>

fern/snippets/redirects.mdx

Lines changed: 40 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,42 @@ 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+
Only add redirects when necessary. Having a long list of redirects can slow down your site since each request must check against all redirect rules before routing the user.
45+
46+
Avoid using redirects for 404 handling or versioning behavior, as Fern provides built-in settings for these use cases.
47+
48+
<AccordionGroup>
49+
<Accordion title="404 handling">
50+
51+
Don't create redirects to send broken links to your homepage:
52+
53+
```yaml title="docs.yml"
54+
redirects:
55+
- source: /docs/event-notifications
56+
destination: / # Don't do this
57+
```
58+
59+
Instead, reach out to Fern to enable automatic homepage redirects, an internal setting that handles broken links without needing manual redirects.
60+
61+
</Accordion>
62+
<Accordion title="Versioning and redirects">
63+
64+
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.
65+
66+
Avoid redirecting from unversioned to versioned URLs:
67+
68+
```yaml title="docs.yml"
69+
redirects:
70+
- source: /docs/event-notifications
71+
destination: /docs/event-notifications/v2 # Don't do this
72+
```
73+
74+
This breaks Fern's version switcher behavior, potentially creating redirect loops or preventing users from navigating between versions.
75+
76+
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.
77+
78+
</Accordion>
79+
</AccordionGroup>

0 commit comments

Comments
 (0)