2023-03-31 00:05:47 -07:00
|
|
|
---
|
|
|
|
|
eleventyNavigation:
|
|
|
|
|
key: Redirects
|
|
|
|
|
title: Redirects
|
|
|
|
|
parent: CodebergPages
|
|
|
|
|
order: 102
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
Redirects can be created with a `_redirects` file with the following format:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# Comment
|
|
|
|
|
from to [status]
|
|
|
|
|
```
|
|
|
|
|
|
2024-06-11 00:51:22 -07:00
|
|
|
- Lines starting with `#` are ignored
|
|
|
|
|
- `from` - the path to redirect from (Note: repository and branch names are removed from request URLs)
|
|
|
|
|
- `to` - the path or URL to redirect to
|
|
|
|
|
- `status` - status code to use when redirecting (default 301)
|
2023-03-31 00:05:47 -07:00
|
|
|
|
|
|
|
|
## Status codes
|
|
|
|
|
|
2024-06-11 00:51:22 -07:00
|
|
|
- `200` - returns content from specified path (no external URLs) without changing the URL (rewrite)
|
|
|
|
|
- `301` - Moved Permanently (Permanent redirect)
|
|
|
|
|
- `302` - Found (Temporary redirect)
|
2023-03-31 00:05:47 -07:00
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
|
|
### Simple redirect
|
|
|
|
|
|
|
|
|
|
Redirects a specific path.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/example https://example.com/ 301
|
|
|
|
|
/path /other-path 301
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### SPA (single-page application) rewrite
|
|
|
|
|
|
|
|
|
|
Redirects all paths to `/index.html` for single-page apps.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/* /index.html 200
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Splats
|
|
|
|
|
|
|
|
|
|
Redirects every path under `/articles` to `/posts` while keeping the path.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/articles/* /posts/:splat 302
|
|
|
|
|
```
|
|
|
|
|
|
2023-11-26 21:45:00 -08:00
|
|
|
Example: `/articles/2022/10/12/post-1/` -> `/posts/2022/10/12/post-1/`
|