405 Method Not Allowed
The request method is known by the server but is not supported by the target resource.
Usually happens because:
- ☑ Sending a POST request to
- ☑ Target resource API route only
🔍 Quick Checklist:
Meaning
The HTTP 405 Method Not Allowed client error status code indicates that the request method is known by the server but is not supported by the target resource. The server must generate an Allow header listing supported methods.
Root Causes
- Sending a POST request to static HTML pages or directories.
- Target resource API route only supports GET/POST but client issued a DELETE request.
| Cause | Frequency |
|---|---|
| Sending a POST request to | ⭐⭐⭐⭐⭐ |
| Target resource API route only | ⭐⭐⭐⭐ |
Common Mistakes
- Failing to supply the mandatory 'Allow' response header field.
- Misconfiguring CORS preflight OPTIONS to return 405 instead of 200/204.
How to Fix
Framework-Specific Examples
Handling unmapped router methods and returning 405 with Allow headers.
app.route('/api/users')
.get((req, res) => res.json([]))
.all((req, res) => {
res.setHeader('Allow', 'GET');
res.status(405).send('Method Not Allowed');
});Server Configuration Examples
Returning 405 redirects for static folder POST requests.
error_page 405 =200 $uri;Prevention
- Always design custom API routing trees to yield 405 fallbacks for unregistered verbs.
- Verify frontend fetch code uses the correct REST methods.
Frequently Asked Questions (FAQ)
Q: What header is mandatory in a 405 response?
The 'Allow' response header field is mandatory. It must contain a comma-separated list of HTTP methods supported by the target resource (e.g. 'Allow: GET, POST').
Q: Why does Nginx return 405 for static file POST requests?
Nginx rejects POST requests to static files (like /index.html) by default because static files cannot process request bodies, returning a 405 Method Not Allowed error.
Q: What is the difference between 405 Method Not Allowed and 501 Not Implemented?
405 means the server *knows* the method but the target path doesn't support it. 501 means the server is *incapable* of supporting the method at all (e.g. a server that doesn't implement PATCH anywhere).
Q: Does a 405 response affect search engine indexing?
Yes. Search engine crawlers only issue GET/HEAD. If your index pages return 405 on GET requests, crawlers will immediately drop those pages from search results.