This feature has been deprecated. It is highly recommended you update to use a Routing file.
301 redirects are inside the 301.txt file at the root of your built files. Redirects are specified using the following syntax:
old-url new-url
Redirect to external domains and wildcard matching with *
. Here’s an example file:
/about.html /about/
/category/* /new-category
/should-have-been-elsewhere/ https://example.com
Redirects will only occur if the redirect-from page/location no longer exists within the site. If the page/location still exists within your site, this will be served instead of performing a redirect.
You can redirect to, but not from a URL fragment (e.g. #example-heading). The fragment is not passed to the server so, it cannot be processed by the redirect.
Migrating to a Routing file#
301.txt redirects still work to ensure backwards compatibility for older sites. Once a .cloudcannon/routing.json
file has been added 301.txt will be ignored. 301.txt offers a subset of the options available in the Routing file. This feature will not be receiving any further improvements.
Upgrading will give access to the following improvements:
- Regex redirects and regex parameters in the location
- Redirects run before all other behaviour allowing easier configuration
- More redirect status codes
- Customise headers on existing routes
- And more coming soon
For the above example, here is the equivalent:
{
"routes": [
{
"from": "/about.html",
"to": "/about/",
"status": 301,
"substitutions": false,
"forced": false
},
{
"from": "/category/*",
"to": "/new-category",
"status": 301,
"substitutions": false,
"forced": false
},
{
"from": "/should-have-been-elsewhere/",
"to": "https://example.com",
"status": 301,
"substitutions": false,
"forced": false
}
]
}