Skip to content

Commit 176bc27

Browse files
committed
Addressing Johnny's suggestions
1 parent 8cb4422 commit 176bc27

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
---
2-
title: redirects file support
2+
title: Redirects file support
33
description: What the _redirect file is and how to use them with a website on IPFS.
44
---
5-
# `_redirects` file support
5+
## Redirects file support
66

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.
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. On top of that, it also provides the ability to change the appearance of a URL, change where content is located without breaking existing links, and enable URL rewriting.
88

99
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/).
1010

1111
For more detailed information, check out the [`_redirects` file support specs](https://github.com/ipfs/specs/blob/main/http-gateways/REDIRECTS_FILE.md).
1212

13-
# Supported HTTP status codes
13+
## Supported HTTP status codes
1414

15-
* `200` - OK (redirect will be treated as a rewrite, returning OK without changing the URL shown in the browser).
16-
* `301` - Permanent redirect (the default status).
17-
* `302` - Found (commonly used for temporary redirects).
18-
* `404` - Not found (can be used redirect to custom 404 pages).
19-
* `410` - Gone (the requested content has been permanently removed).
20-
* `451` - Unavailable for legal reasons.
15+
- `200` - OK (redirect will be treated as a rewrite, returning OK without changing the URL shown in the browser).
16+
- `301` - Permanent redirect (the default status).
17+
- `302` - Found (commonly used for temporary redirects).
18+
- `404` - Not found (can be used redirect to custom 404 pages).
19+
- `410` - Gone (the requested content has been permanently removed).
20+
- `451` - Unavailable for legal reasons.
2121

22-
# How to set up the `_redirects` file
22+
## How to set up the `_redirects` file
2323

2424
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.
2525

26-
## Format of the `_redirects` file
26+
### Format of the `_redirects` file
2727

2828
Each line contained within the `_redirects` file has 3 basic components:
2929

30-
1. The `from` path, this specifies the path to be redirected from.
31-
1. The `to` path, this specifies the path to be redirected to.
32-
1. The `status` component, this part is optional and specifies the HTTP status code that will be returned. (301, 404, etc.)
30+
1. The `from` path. This specifies the path to be redirected from.
31+
1. The `to` path. This specifies the path to be redirected to.
32+
1. The `status` component. This part is optional and specifies the HTTP status code that will be returned. (301, 404, etc.)
3333

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:
34+
For example, if you want to temporarily redirect traffic from your home page to your index page, the `_redirects` file should contain a line that looks something like this:
3535

3636
```
3737
/home /index.html 302 \n
3838
```
3939

4040
The same format is used for all redirects.
4141

42-
# Examples
42+
## Examples
4343

44-
## Catch all and PWA/SPA support
44+
### Catch all and PWA/SPA support
4545

4646
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).
4747

4848
```
4949
/home /index.html 200 \n
5050
```
5151

52-
## Redirect an old URL to a new place
52+
### Redirect an old URL to a new place
5353

5454
The `301` status is a permanent redirect, this is the default status code used when no others are spcified.
5555

@@ -63,15 +63,15 @@ The `302` status is commonly used for temporary redirects.
6363
/home /under-construction.html 302 \n
6464
```
6565

66-
## Add a custom 404 page to your website
66+
### Add a custom 404 page to your website
6767

6868
Use the `_redirects` file support to add a custom 404 page to your website.
6969

7070
```
7171
/home /custom-404.html 404 \n
7272
```
7373

74-
## Placeholders
74+
### Placeholders
7575

7676
Placeholders are named variables that can be used to match path segments in the `from` path and inject them into the `to` path.
7777

@@ -83,14 +83,14 @@ For example, if I wanted to search for an article titled "hello world" that was
8383
/posts/<month>/<day>/<year>/<slug> /articles/<year>/<month>/<day>/<slug> \n
8484
```
8585

86-
# Evaluation
86+
## Evaluation
8787

8888
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).
8989

90-
## No forced redirects
90+
### No forced redirects
9191

9292
Redirect logic will only be evaluated if the requested path is not in the DAG. Any performance impact associated with checking for the existence of a `_redirects` file or evaluating redirect rules will only be incurred for non-existent paths.
9393

94-
# Error handling
94+
## Error handling
9595

9696
If there are any errors reading or parsing the `_redirects` file, the error codes will be returned with an HTTP 500 status code.

0 commit comments

Comments
 (0)