More
More
405 Method Not Allowed
The address exists but does not accept this method, such as POST where only GET works.
- Code
405- Reason phrase
- Method Not Allowed
- Class
- 4xx Client error
- Defined in
- RFC 9110 section 15.5.6
- Cacheable by default
- Yes
What it means
Client error: the problem lies with the request. Repeating it unchanged will normally fail again.
When a server should send it. When the URL exists but does not support the method used, such as DELETE on a read-only resource. The response must list the methods it does accept in an Allow header.
Common causes. Calling an API endpoint with the wrong method, or a form posting to a static page.
What to do. Use a method listed in the Allow header of the response.
How clients and crawlers treat it
Browsers and HTTP clients. Browsers show the body; it mostly surfaces when a form posts to a static file. API clients read Allow to see what is supported.
Google Search. Like every 4xx except 429, it tells Google the content does not exist: an indexed URL is removed from the index, and a new one is not processed. Crawl frequency for the URL gradually drops. Source: Google Search Central, How HTTP status codes, and network and DNS errors affect Google Search.
Caching. Cacheable by default (RFC 9110 section 15.1). With no Cache-Control or Expires header, a cache may still store it and reuse it for a heuristic period, often 10% of the time since Last-Modified, so set Cache-Control explicitly if that is not what you want.
Example response
HTTP/1.1 405 Method Not Allowed Allow: GET, HEAD Content-Type: text/plain Method Not Allowed
How to send 405
location /example {
add_header Allow 'GET, HEAD' always;
return 405;
}
Header always set Allow "GET, HEAD" RewriteEngine On RewriteRule ^example$ - [R=405,L]
header('Allow: GET, HEAD');
http_response_code(405);
echo 'Method Not Allowed';
exit;
res.writeHead(405, { 'Allow': 'GET, HEAD', 'Content-Type': 'text/plain' });
res.end('Method Not Allowed');
# in a view function
return 'Method Not Allowed', 405, {'Allow': 'GET, HEAD'}
Change the paths to suit. In nginx, add_header needs always to apply to error responses.
Related codes
- 501Not ImplementedThe server does not support the method or feature the request needs.
- 404Not FoundNothing exists at this address, or the server will not say that it does.
- 400Bad RequestThe server could not understand the request.
All status codes · All 4xx codes
Names and numbers from the IANA HTTP Status Code Registry. Google Search behaviour as documented by Google Search Central.