Skip to content

Commit a86b0bf

Browse files
committed
Updated name, addressing suggestions
1 parent 11b53bc commit a86b0bf

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ module.exports = {
225225
'/how-to/websites-on-ipfs/link-a-domain',
226226
'/how-to/websites-on-ipfs/introducing-fleek',
227227
'/how-to/websites-on-ipfs/static-site-generators',
228-
'/how-to/websites-on-ipfs/gateway-redirects'
228+
'/how-to/websites-on-ipfs/_redirects-file-support'
229229
]
230230
},
231231
{

docs/how-to/websites-on-ipfs/gateway-redirects.md

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
---
2-
title: Gateway redirects
3-
description: What gateway redirects are and how to use them with a website on IPFS.
2+
title: _redirects file support
3+
description: What the _redirect file is and how to use them with a website on IPFS.
44
---
5+
# `_redirects` file support
56

6-
# THIS IS A DRAFT. DO NOT MERGE.
7+
The `_redirects` file provides support for URL redirects and rewrites for websites hosted on Subdomain or DNSLink gateways. This feature enables support for single-page applications, progressive web applications, custom 404 pages, and avoids link rot when moving to IPFS-backed hosting. As well as the ability to change the appearance of a URL, change where content is located without breaking existing links, and enable URL rewriting.
78

8-
# To do:
9-
1. How to redirect old URL to a new place (301 and 302 redirects)
10-
1. How to use it for PWA/SPA hosting (catch-all 200)
11-
1. How to use it to provide custom `404 not found` pages (superceding what `ipfs-404.html` does - ideally not mention old way)
9+
This `_redirects` implementaion is a subset of pre-existing standards supported by [Cloudflare](https://developers.cloudflare.com/pages/platform/redirects) and [Netlify](https://docs.netlify.com/routing/redirects/).
1210

13-
# Gateway Redirects
14-
15-
Gateway Redirects provide support for URL redirects and rewrites for websites hosted on Subdomain or DNSLink gateways. This feature enables support for single-page applications, and avoids link rot when moving to IPFS-backed hosting.
16-
17-
Using Gateway Redirects, you can change the appearance of a URL, change where content is located without breaking existing links, redirect invalid URLs to a custom 404 page, and enable URL rewriting.
11+
For more detailed information, check out the [`_redirects` file support specs](https://github.com/ipfs/specs/pull/290).
1812

1913
# Supported HTTP status codes
2014

2115
* `200` - OK (redirect will be treated as a rewrite, returning OK without changing the URL shown in the browser).
2216
* `301` - Permanent redirect (the default status).
2317
* `302` - Found (commonly used for temporary redirects).
24-
* `303` - See other (replaces PUT and POST with GET).
25-
* `307` - Temporary redirect (preserves the body and HTTP method of the original request).
26-
* `308` - Permanent redirect (preserves the body and HTTP method of the original request).
2718
* `404` - Not found (can be used redirect to custom 404 pages).
2819
* `410` - Gone (the requested content has been permanently removed).
2920
* `451` - Unavailable for legal reasons.
3021

31-
# How to set up gateway redirects
22+
# How to set up the `_redirects` file
3223

33-
To use Gateway Redirects, 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+
To use the `_redirects` file, 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.
3425

3526
## Format of the `_redirects` file
3627

@@ -40,47 +31,61 @@ Each line contained within the `_redirects` file has 3 basic components:
4031
1. The `to` path, this specifies the path to be redirected to.
4132
1. The `status` component, this part is optional and specifies the HTTP status code that will be returned. (301, 404, etc.)
4233

43-
For example, if I want to redirect a page to a custom `404` page, the `_redirects` file will contain a line that looks something like this:
34+
For example, if for whatever reason I wanted to temporarily redirect traffic from my home page to my index page, the `_redirects` file will contain a line that looks something like this:
35+
4436
```
45-
/<requested page> /custom404.html 404
37+
/home /index.html 302 \n
4638
```
4739

4840
The same format is used for all redirects.
4941

50-
## Placeholders
42+
# Examples
5143

52-
Placeholders are named variables that can be used to match path segments in the `from` path and inject them into the `to` path.
44+
## Catch all and PWA/SPA support
5345

54-
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`
46+
The `200` status will be treated as a rewrite, returning OK without changing the URL shown in the browser. This staus code can be used to build [Progressive Web Apps](https://en.wikipedia.org/wiki/Progressive_web_app) and [Single Page Applications](https://en.wikipedia.org/wiki/Single-page_application).
5547

56-
## Splat
48+
```
49+
/home /index.html 200 \n
50+
```
51+
52+
## Redirect an old URL to a new place
53+
54+
The `301` status is a permanent redirect, this is the default status code used when no others are spcified.
5755

58-
If the `from` path ends with an asterisk (`*`), the rest of the `from` path will be slurped up into the special `:splat` placeholder, which can then be injected into the `to` path.
5956
```
60-
/posts/* /articles/:splat
57+
/index /docs.html 301 \n
6158
```
62-
:::note
63-
Splat logic must only apply to a single trailing asterisk, as it is a greedy match that consumes the remainder of the path. :::
6459

65-
## Comments
60+
The `302` status is commonly used for temporary redirects.
6661

67-
Any line in the `_redirects` file that begins with `#` will be ignored and treated as a comment.
62+
```
63+
/home /under-construction.html 302 \n
64+
```
6865

69-
## Line termination
66+
## Add a custom 404 page to your website
7067

71-
Each line in the `_redirects` file must be terminated with either `\n` or `\r\n`.
68+
Use the `_redirects` file support to add a custom 404 page to your website.
7269

7370
```
74-
/<requsted page> /custom404.html 404 \n
75-
/home /index.html \n
71+
/home /custom-404.html 404 \n
7672
```
77-
# Evaluation
7873

79-
Rules must only be evaluated when hosted on a subdomain or DNSLink gateway, this is to maintain same-origin isolation.
74+
## Placeholders
75+
76+
Placeholders are named variables that can be used to match path segments in the `from` path and inject them into the `to` path.
77+
78+
This is useful for redirecting users to their desired content, even if their search was not completely accurate.
8079

81-
## Order
80+
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`
81+
82+
```
83+
/posts/<month>/<day>/<year>/<slug> /articles/<year>/<month>/<day>/<slug> \n
84+
```
85+
86+
# Evaluation
8287

83-
Rules must be evaluated in order, redirecting or rewriting using the first matching pair.
88+
The `_redirects` file is only supported on subdomain and DNSLink gateways, which provides [unique origin per root CID](https://en.wikipedia.org/wiki/Same-origin_policy).
8489

8590
## No forced redirects
8691

0 commit comments

Comments
 (0)