Skip to content

Commit b6558fe

Browse files
committed
redirects file: clarify query parameters
Related to fix from ipfs/boxo#886
1 parent 1d28680 commit b6558fe

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/http-gateways/web-redirects-file.md

+27-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Web _redirects File Specification
33
description: >
44
Defines how URL redirects and rewrites can be implemented by adding rules to
55
a plain text file stored underneath the root CID of a website.
6-
date: 2023-11-09
6+
date: 2025-03-19
77
maturity: reliable
88
editors:
99
- name: Justin Johnson
@@ -13,10 +13,9 @@ editors:
1313
url: https://fission.codes/
1414
- name: Marcin Rataj
1515
github: lidel
16-
url: https://lidel.org/
1716
affiliation:
18-
name: Protocol Labs
19-
url: https://protocol.ai/
17+
name: Shipyard
18+
url: https://ipshipyard.com
2019
tags: ['httpGateways', 'webHttpGateways']
2120
order: 5
2221
---
@@ -140,14 +139,24 @@ and also applies to a web browser with native `ipfs://` and `ipns://` scheme han
140139

141140
Rules MUST be evaluated in order, redirecting or rewriting using the first matching rule.
142141

142+
The non-existent paths that are being requested should be intercepted and redirected to the destination path and the specified HTTP status code returned. The rules are evaluated in the order they appear in the file.
143+
144+
Any request for an existing file should be returned as is, and not intercepted by the last catch all rule.
145+
143146
## No Forced Redirects
144147

145148
All redirect logic MUST only be evaluated if the requested path is not present in the DAG. This means that 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.
146149

147-
# Error Handling
150+
## Error Handling
148151

149152
If the `_redirects` file exists but there is an error reading or parsing it, the errors MUST be returned to the user with a 500 HTTP status code.
150153

154+
## Query Parameters
155+
156+
Implementations SHOULD retain any dynamic query parameters supplied by the user and pass them along in the `Location` header of the HTTP redirect response.
157+
158+
When merging these user-provided parameters with any static ones defined in the [`To`](#to) field, the user’s dynamic values take precedence, overriding static ones in case of a conflict.
159+
151160
# Security
152161

153162
This functionality will only be evaluated for Subdomain or DNSLink Gateways, to ensure that redirect paths are relative to the root CID hosted at the specified domain name.
@@ -205,6 +214,17 @@ $ ipfs cat /ipfs/QmYBhLYDwVFvxos9h8CGU2ibaY66QNgv8hpfewxaQrPiZj/_redirects
205214
/* /index.html 200
206215
```
207216

208-
The non-existent paths that are being requested should be intercepted and redirected to the destination path and the specified HTTP status code returned. The rules are evaluated in the order they appear in the file.
217+
A dedicated test vector with URL query parameter behavior can be found in `bafybeiee3ltldvmfgsxiqazbatrkbvkl34eanbourajwnavhupb64nnbxa`.
218+
Implementations SHOULD use it for internal testing when [query parameter support](#query-parameters) is desired.
209219

210-
Any request for an existing file should be returned as is, and not intercepted by the last catch all rule.
220+
```
221+
$ ipfs cat bafybeiee3ltldvmfgsxiqazbatrkbvkl34eanbourajwnavhupb64nnbxa/_redirects
222+
# redirect to URL with some static query parameters
223+
/source1/* /target-file?static-query1=static-val1&static-query2=static-val2 301
224+
225+
# redirect to URL where path segments are converted to query parameters
226+
/source2/:code/:name /target-file?code=:code&name=:name 301
227+
228+
# catch-all redirect (test should make request with query parameters, and confirm response preserved them in returned Location header)
229+
/source3/* https://example.net/target3/:splat 301
230+
```

0 commit comments

Comments
 (0)