Contents
Every HTTP request has a method: GET to fetch, POST to submit, PUT and PATCH to update, DELETE to remove, OPTIONS to ask what’s allowed. A 405 tells you the route exists but this method isn’t defined for it. The server should include an Allow header naming the accepted methods, such as Allow: GET, HEAD.
In Laravel the message usually reads The POST method is not supported for route contact. Supported methods: GET, HEAD., and FastAPI returns {"detail":"Method Not Allowed"}.
What causes a 405 error
- The route only accepts one method:
Route::get('/contact', ...)in Laravel while the form sends POST, or a Flask route withoutmethods=["POST"]. - A redirect that changes the method: a POST to
http://or to a URL missing its trailing slash gets a 301 or 302, and the browser repeats it as GET against a POST-only route. - A CORS preflight
OPTIONSrequest between two origins that the app doesn’t handle. - An HTML form trying to send PUT or DELETE directly; forms only do GET and POST.
- A form posting to a static file such as
contact.html, which can’t process POST. - A slightly wrong API URL that matches a different route with different methods.
If you’re a visitor
If the error appears when you submit a form, open the page again from its link and resubmit, rather than reloading the result page. If it keeps happening, tell the site owner: the fault is in how the site defines that route, not in your device.
Fixing it step by step (developers)
- Find the allowed methods from the headers:
curl -i -X POST https://example.com/api/items
curl -i -X OPTIONS https://example.com/api/items
- Check your route definitions. In Laravel, over SSH:
php artisan route:list --path=api/items
In Flask, declare the method explicitly:
@app.route("/api/items", methods=["GET", "POST"])
def items():
...
- Use the final URL in the form
actionor infetch, withhttps://and the same trailing-slash style the site uses, so the request never goes through a redirect. If you need a redirect that keeps POST, use 307 or 308 rather than a 301 redirect. - Use method spoofing in Laravel forms:
<form method="POST" action="/posts/7">
@csrf
@method('PUT')
</form>
- Handle
OPTIONSrequests: enable CORS in your framework, such asconfig/cors.phpin Laravel or thecorspackage in Express. - Read the logs: in cPanel open Metrics → Errors; for Laravel check
storage/logs/laravel.log; for Node.js and Python apps check the log file set in the app’s settings.
If the URL doesn’t exist at all you’ll get a 404 rather than a 405, which helps tell the two problems apart.
Prevention
- Write a simple test for each API endpoint that checks the accepted methods.
- Document the methods each route allows and return a correct
Allowheader. - Settle on one URL style (https, trailing slash or not) and use it in every request.
On ArabyHost
AI/Developer plans give you SSH jailed in CageFS, PHP 8.1-8.3 with Composer, Node.js 20 and 24, and Python 3.9-3.12 through the CloudLinux selectors and Phusion Passenger, so you can run php artisan route:list and read logs directly. See the Laravel deployment guide and the Node.js deployment guide. LiteSpeed is the web server and reads .htaccess like Apache, and the Araby AI assistant can read your error log and explain why a request was rejected.
FAQ
What's the difference between 405 and 404?
With 404 nothing exists at the URL. With 405 the URL exists and works, just with a different method, and the server usually sends an Allow header listing the methods it accepts.
Why does my POST turn into a GET and return 405?
On a 301 or 302 redirect, such as http to https or adding a trailing slash, browsers resend the request as GET. Call the final URL directly, or use a 307 or 308 redirect, which keeps the method.
How do I send PUT or DELETE from an HTML form?
HTML forms only support GET and POST. In Laravel, send POST and add @method('PUT') inside the form, or use fetch in JavaScript with the method you need.