Skip to content
HTTP status codes3 min read

405 Method Not Allowed

405 Method Not Allowed

Short answer

A 405 Method Not Allowed error means the server found the URL but doesn't accept the HTTP method used, for example a POST sent to a route defined for GET only. Fix it by matching the method to the route definition, or by avoiding redirects that turn POST into GET.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What causes a 405 error
  2. If you’re a visitor
  3. Fixing it step by step (developers)
  4. Prevention
  5. On ArabyHost

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 without methods=["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 OPTIONS request 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)

  1. 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
  1. 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():
    ...
  1. Use the final URL in the form action or in fetch, with https:// 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.
  2. Use method spoofing in Laravel forms:
<form method="POST" action="/posts/7">
  @csrf
  @method('PUT')
</form>
  1. Handle OPTIONS requests: enable CORS in your framework, such as config/cors.php in Laravel or the cors package in Express.
  2. 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 Allow header.
  • 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.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.