405 Method Not Allowed
4xx client error
The URL exists, but it doesn't support the HTTP method used.
405 means the route is right but the verb is wrong — a POST to an endpoint that only accepts GET, or a DELETE the server doesn't implement for that resource. The response must include an Allow header listing the methods the resource does support.
| Class | 4xx Client Error |
|---|---|
| Retry? | No — change the request first |
| Cacheable by default | Yes (heuristically, per RFC 9110) |
| Response body | Allowed |
| Defined in | RFC 9110 §15.5.6 — 405 Method Not Allowed |
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
Content-Type: application/json
Content-Length: 30
{"error":"Method Not Allowed"}Common causes
- Sending POST to a static file or a read-only endpoint.
- A form submitting to a URL whose handler only defines GET.
- Next.js route handlers:
route.tsexportsGETbut notPOST. - Static hosts (S3, GitHub Pages, most CDNs) only serve GET and HEAD.
How to fix it
- Read the
Allowheader in the response to see which methods are accepted. - Define a handler for the method on the server, and for OPTIONS if browsers call the endpoint cross-origin.
- Point form submissions and API calls at a server endpoint, not a static file.
Useful here: CORS errors explained
Send a 405 from your server
res.set("Allow", "GET, HEAD");
res.status(405).json({ error: "Method Not Allowed" });return Response.json({ error: "Method Not Allowed" }, { status: 405, headers: { "Allow": "GET, HEAD" } });return {"error": "Method Not Allowed"}, 405, {"Allow": "GET, HEAD"}w.Header().Set("Allow", "GET, HEAD")
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)add_header Allow "GET, HEAD" always; return 405;
Check what a URL returns
Print just the status line from the command line, or check a whole list of URLs at once, with their response headers, in the HTTP Status Checker.
curl -sI https://example.com/your-path | head -n 1
Frequently asked questions
405 vs 404?
404: no such resource. 405: the resource exists, but not for this method. Return 405 with an Allow header so clients can correct themselves.
405 vs 501?
405: this resource doesn't support the method. 501: the server doesn't implement the method for any resource.