You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/websites-on-ipfs/redirects-and-custom-404s.md
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,9 @@ Redirect logic will only be evaluated if the requested path is not in the [DAG](
20
20
21
21
## How to set up
22
22
23
-
To define rules executed when requested path is not found in DAG, there must be a file named `_redirects` stored underneath the root CID of the website. This `_redirects` file must be a text file containing one or more lines that follow the format explained below.
23
+
To define rules that will be executed when the requested path is not found in the DAG, there must be a file named `_redirects` stored underneath the root CID of the website. This `_redirects` file must be a text file containing one or more lines that follow the format explained below.
24
24
25
-
## Format of the `_redirects` file
25
+
###Format of the `_redirects` file
26
26
27
27
Each line contained within the `_redirects` file has 3 basic components:
28
28
@@ -34,13 +34,12 @@ from to [status]
34
34
1. The `to` path. This specifies the path to be redirected to.
35
35
1. The `status` component. This part is optional and specifies the HTTP status code that will be returned. (301, 404, etc.)
36
36
37
-
For example, if you removed `home.html` and want to temporarily redirect traffic from `home.html`page to your `index.html` page, the `_redirects` file should contain a line that looks something like this:
37
+
For example, if you removed `home.html` and want to temporarily redirect traffic from `home.html` to `index.html`, the `_redirects` file should contain a line that looks something like this:
38
38
39
39
```plaintext
40
40
/home.html /index.html 302
41
41
```
42
42
43
-
44
43
### Status codes
45
44
46
45
-`200` - OK (redirect will be treated as a rewrite, returning payload from alternative content path without changing the URL shown in the browser).
@@ -54,15 +53,15 @@ For example, if you removed `home.html` and want to temporarily redirect traffic
54
53
55
54
Placeholders are named variables that can be used to match path segments in the `from` path and inject them into the `to` path.
56
55
57
-
This is useful for redirecting users to their desired content, even if the way your website is organized changed.
56
+
This is useful for redirecting users to their desired content, even if the way your website is organized changed.
58
57
59
58
For example, if I wanted to search for an article titled "hello world" that was written on June 15, 2022, I could search for it like this: `/posts/06/15/2022/hello-world` and be redirected to `/articles/2022/06/15/hello-world`
There is also special catch-all placeholder named `:splat` which represents everything captured via `*`.
64
+
There is also a special catch-all placeholder named `:splat` which represents everything captured via `*`.
66
65
67
66
```plaintext
68
67
/blog/* /new-blog/:splat 302
@@ -77,7 +76,6 @@ There is no overwrite/shadowing: the file is evaluated only when requested path
77
76
For more detailed information about supported features, check out the [`_redirects` file specification](https://github.com/ipfs/specs/blob/main/http-gateways/REDIRECTS_FILE.md).
78
77
:::
79
78
80
-
81
79
## Examples
82
80
83
81
### Catch all and PWA/SPA support
@@ -93,7 +91,7 @@ Opening `/app/this-does-not-exist` will return HTTP 200 response with content fr
93
91
### Redirect an old URL to a new place
94
92
95
93
The `301` status is a permanent redirect, this is the default status code used when no code is specified.
96
-
Below two rules mean the same:
94
+
The two rules below mean the same thing:
97
95
98
96
```plaintext
99
97
/old/docs.html /new/documentation.html
@@ -106,12 +104,12 @@ The `302` status is commonly used for temporary redirects.
106
104
/home /under-construction.html 302
107
105
```
108
106
109
-
For advanced and catch-all redirects, see [Placeholders](#placeholders) below.
107
+
For advanced and catch-all redirects, see [Placeholders](#placeholders).
110
108
111
109
### Add a custom 404 page to your website
112
110
113
111
Since the `_redirects` is evaluated only when requested path does not exist,
114
-
it is possibleto define a custom 404 page for your website:
112
+
it is possible to define a custom 404 page for your website:
0 commit comments