Config, Redirects & Deploys
netlify.toml
[build]
command = "npm run build"
publish = "dist"
[build.environment]
NODE_VERSION = "20"
# Secrets (API keys) belong in the UI/CLI, not here — this file is committed to git
[[redirects]]
from = "/old-blog/*"
to = "/blog/:splat"
status = 301
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
force = true # applies even though /index.html isn't the literal requested path
[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
# Per-context env vars — deploy previews can point at a different API than prod
[context.deploy-preview.environment]
API_URL = "https://staging-api.example.com"
[context.production.environment]
API_URL = "https://api.example.com"CLI & Local Dev
netlify login
netlify init # link a repo to a Netlify site
netlify dev # local server emulating Functions, redirects, env vars
# — detects & proxies your framework's own dev server
netlify deploy # draft deploy, unique preview URL
netlify deploy --prod # deploy straight to production
netlify env:set API_KEY "secret-value"
netlify open # open the site's dashboard in a browserRollback
Every deploy's built output is retained and immutable — rolling back means selecting an earlier deploy in the Deploys tab and clicking "Publish deploy" to instantly make it live again, with zero rebuild time.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free