_redirects files for Netlify in your Nuxt.js projects.
This module supports the creation of redirects and header rules for your Netlify site: you can easily configure custom headers, basic auth, redirect instructions and rewrite rules from your nuxt config file.
node >= 10 and
nuxt >= 2 are required.
npm install --save-dev @aceforth/nuxt-netlify
yarn add --dev @aceforth/nuxt-netlify
@aceforth/nuxt-netlify to the
buildModules section of
⚠️ If you are using Nuxt
< 2.9.0, use
The default configuration will generate an empty
_redirects file and a
_headers file with some caching and security headers:
# _headers/*Referrer-Policy: originX-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=block/_nuxt/*Cache-Control: public, max-age=31536000, immutable/sw.jsCache-Control: no-cache
/_nuxt/*reference automatically changes with the value of
The headers object represents a JS version of the Netlify
_headers file format. You should pass in a object with string keys (representing the paths) and an array of strings for each header. For example:
You can add extra headers as follows:
const pkg =netlify:headers:'/*':'Access-Control-Allow-Origin: *'`X-Build: `'/favicon.ico':'Cache-Control: public, max-age=86400'
that will generate:
# _headers/*Referrer-Policy: originX-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockAccess-Control-Allow-Origin: *X-Build: 1.0.1/_nuxt/*Cache-Control: public, max-age=31536000, immutable/sw.jsCache-Control: no-cache/favicon.icoCache-Control: public, max-age=86400
You can also add redirects, as many as you like. You should pass in an array of objects with the redirection attributes. For example:
netlify:redirects:from: '/home'to: '/'from: '/my-redirect'to: '/'status: 302force: truefrom: '/en/*'to: '/en/404.html'status: 404from: '/*'to: '/index.html'status: 200from: '/store'to: '/blog/:id'query:id: ':id'from: '/'to: '/china'status: 302conditions:Country: 'cn,hk,tw'
# _redirects/home / 301/my-redirect / 302!/en/* /en/404.html 404/* /index.html 200/store id=:id /blog/:id 301/ /china 302 Country=cn,hk,tw
See the configuration section for all available options.
Documentation & Support
- 📄 If you want extra details of how to configure and use this project, the full documentation is available at https://marquez.co/docs/nuxt-netlify/.
- 🐞 For Bug reports or Feature requests, use the Issues section.
- 💬 For questions, you can also use the Issues section.
- 🚀 You may also want to follow me on Twitter.
This project is sponsored by me, a Full Stack Developer. If you require Professional Assistance on your project(s), please contact me at https://marquez.co.
Code of Conduct
Everyone participating in this project is expected to agree to abide by the Code of Conduct.
Code released under the MIT License.