|
1 | 1 | 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. |
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 |
|
6 | 6 | <CodeBlock title="docs.yml"> |
@@ -38,3 +38,42 @@ If your docs are hosted on a subpath (like `buildwithfern.com/learn`), include t |
38 | 38 | <ParamField path="permanent" type="boolean" required={false}> |
39 | 39 | Toggle between **permanent** and **temporary** redirects (default `false`). When true, the status code is 308. When false, the status code is 307. |
40 | 40 | </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