Syntax for the Netlify configuration file #
If you specify your redirect rules in your Netlify configuration file, you can use a more structured configuration format with additional capabilities such as signed proxy redirects. In a netlify.toml
file, we use TOML’s array of tables to specify each individual redirect rule. The following keywords are available:
from
: The path you want to redirect.to
: The URL or path you want to redirect to.status
: The HTTP status code you want to use in that redirect;301
by default.force
: Whether to override any existing content in the path or not;false
by default. Visit the shadowing instructions for more details.query
: Query string parameters REQUIRED to match the redirect. Visit the query parameters instructions for more details.conditions
: Conditions to match the redirect, including country, role, and cookie presence conditions.headers
: Additional request headers to send in proxy redirects.signed
: Name of an environment variable for signed proxy redirects.
You can specify any number of rules in your netlify.toml
following that format:
toml
[[redirects]]
from = "/old-path"
to = "/new-path"
status = 301
force = false
query = {path = ":path"}
conditions = {Language = ["en"], Country = ["US"], Role = ["admin"]}
## This rule redirects to an external API, signing requests with a secret
[[redirects]]
from = "/search"
to = "https://api.mysearch.com"
status = 200
force = true # COMMENT: ensure that we always redirect
headers = {X-From = "Netlify"}
signed = "API_SIGNATURE_TOKEN"