Provide support for URL redirects and rewrites for web sites hosted on Subdomain or DNSLink Gateways, thus enabling support for single-page applications (SPAs), and avoiding link rot when moving to IPFS-backed hosting.
Web sites often need to redirect from one URL to another, for example, to change the appearance of a URL, to change where content is located without breaking existing links (see Cool URIs don't change, link rot), to redirect invalid URLs to a pretty 404 page, or to enable URL rewriting. URL rewriting in particular is a critical feature for hosting SPAs, allowing routing logic to be handled by front end code. SPA support is the primary impetus for this RFC.
Currently the only way to handle URL redirects or rewrites is with additional software such as NGINX sitting in front of the Gateway. This software introduces operational complexity and decreases the uniformity of experience when navigating to content hosted on a Gateway, thus decreasing the value proposition of hosting web sites in IPFS.
This IPIP proposes the introduction of redirect support for content hosted on Subdomain or DNSLink Gateways, configured via a _redirects
file residing underneath the root CID of the web site.
Allow developers to configure redirect support by adding redirect rules to a file named _redirects
stored underneath the root CID of their web site.
The format for this file is similar to those of Netlify and Cloudflare Pages but only supporting a subset of their functionality.
The format for the file is from to [status]
.
from
- specifies the path to intercept (can include placeholders and a trailing splat)to
- specifies the path or URL to redirect to (can include placeholders or splat matched in from
)status
- optional HTTP status code (301 if not specified)Rules in the file are evaluated top to bottom.
For performance reasons this proposal does not include forced redirect support (i.e. redirect rules that are evaluated even if the from
path exists). In other word, redirect logic will be evaluated if and only if the requested path does not exist. If the requested path exists, we won't even check for the existence of the _redirects
file.
If a _redirects
file exists but is unable to be processed, perhaps not even parsing correctly, errors will be returned to the user viewing the site via the Gateway.
The detailed specification is added in [web-redirects-file].
QmQyqMY5vUBSbSxyitJqthgwZunCQjDVtNd8ggVCxzuPQ4
See spec for testing details.
Popular services today such as Netlify and Cloudflare Pages allow developers to configure redirect support
using a _redirects
file hosted at the top level of the web site. While we do not intend to provide all of the same functionality, it seems desirable to use a similar approach to provide a meaningful subset of the functionality offered by these services.
Provides general URL redirect and rewrite support, which enables three important features:
If by some chance developers are already hosting sites that contain a _redirects
file that does something else, they may need to update the contents of the file to match the new functionality. Errors returned to the user due to parsing errors will guide them regarding the required updates.
_redirects
file or a more general configuration file, there is nothing precluding IPFS from allowing developers to configure redirect support in an app manifest later on._redirects
only if the DAG is missing a requested path. Never the less, if a more generic metadata facility were to be introduced in the future, it may make sense to reconsider how redirect rules are specified.Copyright and related rights waived via CC0.
We gratefully acknowledge the following individuals for their valuable contributions, ranging from minor suggestions to major insights, which have shaped and improved this specification.