405 Error Explained: Causes, Fixes, and Prevention Tips

Every HTTP status code tells a story about what’s happening between a client (e.g. web browser) and a server. Some stories are simple; 200 means success, 404 means the page doesn’t exist. But when you see 405 Method Not Allowed, the story is a little more interesting.
Let’s break down what the 405 error means, why it happens, and how to troubleshoot it
What the 405 Status Code Means
The 405 Method Not Allowed response happens when a client (like your browser or an API tool) makes a request using an HTTP method that the server does not allow for that resource.
For example:
- A form submission sends a POST request, but the server only accepts GET for that URL.
- A script sends a PUT request, but the endpoint is configured to only allow POST and DELETE.
The important detail is that the page you’re trying to reach exists, but the request method used to interact with it is not permitted by the server.
What Might Cause a 405 Error
The 405 error doesn’t always have a single, obvious cause. It can come from the way a request is made, how the server is configured, or even from extra security layers in place. Here are the most common situations that would trigger it:
1. Wrong HTTP Method
Every resource on a server is set up to accept certain HTTP methods. For example:
- A product page might allow GET (to fetch details) but reject POST (to submit data).
- An API endpoint might allow POST to create a new item but return a 405 if you try DELETE.
A common scenario is when a developer sends a POST request to a URL that was only designed to handle GET. The server recognizes the resource, but since the method isn’t supported, it responds with 405.
This is one of the most frequent causes, especially when working with forms, APIs, or scripts that interact with web services.
2. Misconfigured Server Rules
Web servers like Apache, Nginx, and IIS give administrators control over which HTTP methods are allowed. Configuration directives such as Apache’s Limit or Nginx’s limit_except can explicitly block certain verbs.
For instance:
- A server admin might configure a site to only allow GET and POST, blocking PUT and DELETE for security.
- If the rules are too strict (or miswritten), legitimate requests can be rejected with a 405.
This can often happen after changes to .htaccess files, server blocks, or IIS request filtering settings. Even a small typo or overlooked directive can result in methods being unintentionally blocked.
3. API Restrictions
APIs are designed with strict method rules. In a RESTful API, different HTTP verbs usually correspond to specific actions:
- GET → Retrieve data
- POST → Create new data
- PUT/PATCH → Update existing data
- DELETE → Remove data
If a developer calls an endpoint with the wrong method, such as sending a PUT to a URL that only allows POST, the server responds with a 405.
This is intentional, as APIs are meant to enforce consistent interaction patterns. For example, GitHub’s API won’t let you DELETE a repository by mistake through a wrong method call, it requires the correct verb, or you’ll get a 405 response.
4. Incorrect Form or AJAX Setup
Web forms and JavaScript (AJAX) requests are another common source of 405 errors:
- A form might have the method=”post” attribute, but the server only allows GET on that URL.
- JavaScript’s fetch() or XMLHttpRequest may be coded to send a PUT request when the backend only supports POST.
Since browsers handle form and AJAX submissions automatically, even a small mismatch in how a request is coded versus how the server expects it can trigger this error.
Beginners often encounter this when learning to set up forms in PHP or when working with frontend frameworks that make API calls.
5. Security Tools
Even when a server is configured correctly, security layers can step in and block requests. Examples include:
- Web Application Firewalls (WAFs): These monitor incoming traffic and may reject methods like PUT, DELETE, or TRACE to reduce the risk of attacks.
- Security Plugins: In platforms like WordPress, some plugins disable certain methods site-wide to prevent unauthorized requests.
In these cases, the server itself might support the method, but the request gets intercepted before it reaches the application. This often leads to confusion because logs may show the server “rejecting” the method when in reality it’s a security layer doing the filtering.
How 405 Differs From Similar Status Codes
At first glance, the 405 error can be mistaken for other client and server errors. But the details matter, and knowing the differences will help you diagnose it correctly.
404 Not Found
- What it means: The server can’t find the resource you’re requesting.
- Example: You try visiting example.com/page.html, but the page doesn’t exist at all.
- Key difference from 405: With a 404, the problem is the resource itself not being there, whereas with a 405, the resource exists—you’re just using the wrong method to interact with it.
403 Forbidden
- What it means: The resource exists, but the server is blocking you from accessing it.
- Example: You may be trying to view a private directory without proper permissions.
- Key difference from 405: A 403 is about access rights, while a 405 is about method restrictions.
501 Not Implemented
- What it means: The server doesn’t recognize or support the HTTP method at all, for any resource.
- Example: A server that doesn’t support PATCH requests will throw this error no matter what resource you try.
- Key difference from 405: A 501 applies to the entire server, while a 405 applies only to a specific resource.
Diagnosing the 405 Error
It can be tricky to diagnose the 405 because the server is acknowledging the resource exists, but it’s refusing to process the request the way it was sent. To track down the root cause, it helps to work through the problem step by step.
1. Check the Allowed Methods
When a server returns a 405, the response should include an Allow header listing which methods are supported for that resource. This is the server’s way of saying, “You can’t do that, but here’s what you can do.”
Example:
HTTP/1.1 405 Method Not Allowed
Allow: GET, POST
- If you tried PUT, this response tells you that only GET and POST are valid.
- You can see this using browser developer tools (Network tab) or a tool like Postman.
- Automating header checks in a debugging workflow can quickly highlight misaligned method usage across multiple endpoints.
2. Review Server Logs
Logs are often the fastest way to uncover the cause as they will typically give a direct explanation of why the request was rejected and confirm it isn’t a deeper connectivity issue.
- Apache: Check the error_log file, usually in /var/log/apache2/ or /var/log/httpd/.
- Nginx: Review error.log and access.log, usually in /var/log/nginx/.
- IIS: Open Event Viewer or check IIS log files under %SystemDrive%\inetpub\logs\LogFiles\.
Logs may show entries like:
client sent an unsupported method (PUT) to /index.php
3. Test the Endpoint
Tools like cURL or Postman are invaluable for confirming which methods actually work. Testing endpoints this way rules out guesswork and gives you clear visibility into how the server responds to different requests.
Using cURL:
curl -i -X GET https://example.com/resource
curl -i -X POST https://example.com/resource
curl -i -X PUT https://example.com/resource
- If GET and POST succeed but PUT fails with a 405, you’ve identified the mismatch.
Postman gives a visual interface where you can toggle request methods and instantly see responses, making it more beginner-friendly.
4. Check Your Code
If the server allows the method but you’re still getting a 405, the problem may be in your application code.
Forms: Make sure the
