Redirects, 404 and caching
On a static site, the _redirects, 404.html and _headers files at the root of the output, in the Netlify format, and the default Cache-Control.
A static site reads three special files from the root of the output directory, in the same format as Netlify and Cloudflare Pages. A site coming from another host keeps its old URLs, its 404 page and its headers. In SSR mode your server answers, and these files don’t apply.
A new deployment takes effect within 1 minute. The _redirects and _headers files are never served as files: requests to them respond 404. Owbase reads them from the site itself from time to time, and those reads show up in the logs like any other request.
Redirects (_redirects)
Section titled “Redirects (_redirects)”For many rules, regex, per-domain conditions, scheduling, statistics or an SSR site, use the Redirects module, evaluated at the edge before the request reaches the site. The module’s rules run first; _redirects still applies after them, unless the site turns it off (redirectsFile: false).
One rule per line: source, destination and, optionally, the status (default 301). # comments out the rest of the line.
# Old URLs indexed by Google/index.php/normas-internas/ /normas-internas//unidade-taboao/ /unidades/taboao/ 308/index.php/* /:splat 301/post/:year/:slug /blog/:slug 301/promo-2019 / 410/blog/* https://blog.example.com/:splat 302
# Single-page app: everything that isn't a file goes to index.html/* /index.html 200- Source: starts with
/. A trailing*matches the rest of the path (:splatin the destination), and:namematches one segment. Matching ignores the trailing slash and letter case, and accepts accented characters encoded or not. *in the middle of a name:*only matches whole segments, after a/, as on Netlify./wp-sitemap-*doesn’t match/wp-sitemap-posts-page-1.xml(the line is ignored). List the explicit path (/wp-sitemap-posts-page-1.xml) or use:file, which matches a whole segment (/:file).- Destination: a path on the site or an
https://URL. The request’s query string carries over, unless the destination has one. - Status:
301,302,303,307and308redirect, and410responds “gone”. They apply even when the file exists.200serves the destination in place of the path, without changing the URL (rewrite).404serves the destination with status 404.- Those two only apply when the path has no file. With a trailing
!(200!), they always apply.
- The first matching rule wins, in file order. Lines Owbase doesn’t understand are ignored and the others still apply: conditions on the query (
id=:id), country, language or cookie, and an external destination in a200rule.
With a fallback file set (Frameworks), every path has a response, so 200 and 404 rules without ! never apply. To combine a SPA with redirects, leave the fallback empty and put /* /index.html 200 at the end of _redirects.
404 page (404.html)
Section titled “404 page (404.html)”With a 404.html at the root of the output, every missing path responds with it and with status 404, which Google handles correctly (with 200 it would flag the page as a soft 404). The 410 from _redirects uses this page too.
Without a 404.html, a missing path responds 404 with a neutral, unbranded page, in Portuguese or English depending on the visitor’s browser.
Headers and caching (_headers)
Section titled “Headers and caching (_headers)”When your _headers doesn’t set Cache-Control, Owbase uses this default:
| File | Cache-Control |
|---|---|
Script, stylesheet, font, image or video with a hash in the name (index-BXk3a9Zq.js, app.3f9a8b7c.css) or a version in the query (site.css?v=12) |
public, max-age=31536000, immutable |
| Everything else (HTML, images without a hash, 404 pages) | public, max-age=0, must-revalidate |
max-age=0, must-revalidate doesn’t download the file again on every visit: the browser asks whether it changed (If-Modified-Since) and gets 304 when it didn’t.
To change the default or add headers, use a _headers file. Each path goes on its own line, with the headers indented below it:
/* X-Frame-Options: DENY Referrer-Policy: strict-origin-when-cross-origin
/img/* Cache-Control: public, max-age=86400
/downloads/* Content-Disposition: attachmentPaths follow the same rule as the _redirects source (trailing *, :name). When more than one block matches a path, all of them apply, and for the same header the last block wins. Transport and content headers can’t be changed (Content-Length, Content-Encoding, Set-Cookie, Location, ETag, Last-Modified and X-Owbase-*): the line is ignored.