Find out why the page won't take that kind of request
405 Method Not Allowed means the server recognizes the request's method, such as POST, but the address doesn't accept it. On a website, look first at forms: one that submits to a page that only serves GET, one whose submission passes through a redirect that turns its POST into a GET, or one on a host that only serves files and has nothing to run. HTTP requires every 405 to list the methods the address accepts in an Allow header, which tells you what the server expected, though a static file server may leave it out.
Why an address refuses the method
The form posts to the wrong address
The form's action points at a page that only displays content, or your app's route handles GET but not POST. The page opens fine in a browser and refuses the submission.
A redirect turned POST into GET
When a form posts to an address that answers with a 301 or 302 redirect, browsers may resend it to the new address as a GET, which a POST-only handler refuses. A form still aimed at the http or www version of your site can hit this.
A static host received a form
A host that only serves files has no code to run for a POST and can refuse it. The form needs a handler: a server route, a serverless function or a form service.
HEAD isn't handled
HTTP requires general-purpose servers to support GET and HEAD. An app that answers only GET can pass a browser check and still return 405 to tools that test addresses with HEAD.
A method switched off on purpose
Servers often disable TRACE for security, so a 405 for TRACE in your logs is expected and needs no fix.
RFC 9110 requires the Allow header on every 405, requires GET and HEAD support in section 9.1, and lets browsers change POST to GET on a 301 in its note on redirects. MDN gives TRACE as a method servers commonly disallow.
Compare the methods the address accepts
# HEAD request: the status and any Allow header
curl -sI https://yoursite.com/contact | grep -iE '^(HTTP|allow)'
# POST request, as the form sends it: print only the response headers
curl -s -o /dev/null -D - -d "name=test" https://yoursite.com/contact | grep -iE '^(HTTP|allow|location)'
Read the Allow header and any redirect
The Allow header lists what the address accepts, such as
Allow: GET, HEAD. If POST isn't in the list, the form is aimed at a page that can't take a submission, so find the address your handler listens on and point the form there. An empty Allow header means the address accepts nothing right now, which RFC 9110 allows when a resource is switched off in the configuration. If the 405 has no Allow header at all, the server skipped the rule, which static file servers do: nginx refuses any POST to a plain file, as its static module shows, and answers 405 Not Allowed. Treat that as the static host case above.If the POST gets a 301 or 302 with a
Locationheader instead, the form's address is out of date. The browser follows the redirect, may resend the submission as a GET, and the handler refuses it, so the visitor's data never arrives. Point the form at the final address, or use a 307 or 308 redirect, which keeps the method.
How to fix a 405 Method Not Allowed error
- Point the form at its handlerSet the form's action to the exact address of the route that processes it, with the same scheme, host and trailing slash, so no redirect sits between the form and the handler.
- Register the method on the routeIf the route should accept POST, add a POST handler to it, and check which methods your framework's route definition lists for that path.
- Answer HEAD wherever you answer GETRoute HEAD requests to the same handler as GET and send the headers without a body, as HTTP requires.
- Give static forms somewhere to postOn a host that only serves files, send the form to a serverless function or a form service that accepts POST, and keep the page itself static.
Frequently asked questions
Why does curl -I return 405 when the page loads in a browser?
curl -I sends a HEAD request, and browsers send GET, so your app handles GET but not HEAD. Some link checkers and uptime tools send HEAD too, so add it rather than working around it. Until then, curl -s -o /dev/null -D - sends a GET and prints the headers.
Why did my contact form start showing 405 after moving to HTTPS?
The form still posts to the http address, and the redirect to https turns the submission into a GET that the handler refuses. Change the form's action to the https address, and check other forms and scripts that post to a hard-coded URL.
What's the difference between 405 and 501?
A 405 means the server knows the method but this address doesn't accept it. A 501 means the server doesn't recognize the method or support it for any address. RFC 9110 defines 501.
Watch for errors your visitors hit
- Website reliabilityHear about it when your site goes down, not days later from a customer.
- HTTP to HTTPS redirectSend HTTP requests to their HTTPS destination and avoid conflicting redirect rules.
- www and non-www redirectChoose www or non-www and keep redirects, canonical tags and certificates in step.
- 400 Bad RequestFind which layer refused the request and which part of it failed, such as a cookie, a header or the body.