|
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,40 @@ 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 | +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