404 and redirects with netlify?
I'm struggling with my redirects instead resolving as 404s
I want to 404 except for known redirects.
I have a static site, any ideas?
5 Replies
Hi @exopenguin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, there's a specific solution for handling redirects and 404s with Netlify and Nuxt static sites.
The issue you're experiencing is likely related to the ordering of redirect rules in your
netlify.toml file. According to Netlify redirects not working with Nuxt 3 static site, if you have a catch-all 404 redirect rule placed before your other redirect rules, it will intercept all requests and prevent your intended redirects from working.
Solution
Make sure your redirect rules in netlify.toml are ordered correctly - place your specific redirects before the catch-all 404 rule:
The catch-all 404 rule should always be at the end of all your redirect rules. If it's placed at the beginning, it will match all routes before your specific redirects have a chance to be evaluated.
This is a Netlify configuration issue rather than a Nuxt issue - the redirect rules are processed by Netlify before Nuxt handles the routing.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@393928198943145984> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
surely that would render all pages with a 404?
@kapa.ai surely that would render all pages with a 404?
Let me check the knowledge base for you again. One moment! :books:
----------------------
You're right to question that! Let me clarify - the catch-all 404 rule with
from = "/*" and status = 404 only applies when no other route matches. It doesn't render all pages with a 404.
According to Netlify redirects not working with Nuxt 3 static site, Netlify processes redirect rules in order from top to bottom. When a request comes in:
1. Netlify checks each redirect rule sequentially
2. If a specific redirect matches (like /old-path → /new-path), it executes that redirect
3. If your Nuxt static site has a matching page/route, that page is served normally
4. Only if nothing else matches does the catch-all /* rule trigger, sending the request to your 404 page
The key is that the catch-all 404 rule acts as a fallback - it only catches requests that don't match any of your:
- Specific redirect rules (defined above it)
- Actual pages in your static site
So your existing pages will continue to work normally, your defined redirects will work, and only truly non-existent routes will hit the 404 page. The ordering ensures your specific redirects are evaluated before the catch-all fallback.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@393928198943145984> Kapa.ai is still learning and improving, please let me know how I did by reacting below.