405

Method Not Allowed

Official Substatus codes
The method used for the request is not allowed

Specification of the HTTP status code 405

The 405 Method Not Allowed status code indicates that the method received in the request-line is known by the origin server but not supported by the target resource. The origin server MUST generate an Allow header field in a 405 Method Not Allowed response containing a list of the target resource's currently supported methods. A 405 Method Not Allowed response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls

Source / Quote by: The 405 Method Not Allowed HTTP Status Code is specified by section 6.5.5 of RFC7231.

How to throw a 405 statuscode with PHP?

To throw the HTTP status code 405 on a web page, the PHP function http_response_code can be used. The syntax is as follows: http_response_code(405) (PHP 5 >= 5.4.0, PHP 7, PHP 8)

Test the 405 HTTP status code

In order to be able to display the HTTP status code (in this case 405 Method Not Allowed) and other information on the client side, the development console must be opened with F12. Afterwards you have to navigate to the tab "Network". Now you can open the page, in the network tab you should see the web page (example index.php). This must be selected and then the Herder section must be selected. Here the user will see the following result:

Status code 405 Method Not Allowed
Overview
URL: https://http-statuscode.com/errorCodeExample.php?code=405
Status: 405 Method Not Allowed
Those: Network
IP address: XX.XX.XX.XX
Status code 405 Method Not Allowed

How do I solve the problem with the 405 status code?

The solution to the HTTP status code 405 Method Not Allowed problem is to make the necessary changes on the client or server side. Below I will explain several approaches that can help in solving the problem:

  1. Check the supported HTTP methods: The 405 Method Not Allowed status code occurs when the client uses an HTTP method that is not supported by the server. Make sure you are using the correct method, such as GET, POST, PUT, or DELETE, depending on the action you want to perform. Check the API or server documentation to determine the supported methods for the resource in question.
  2. Check the URL: It is possible that the URL is incorrectly formatted or invalid, resulting in a 405 Method Not Allowed error. Make sure the URL is correct and points to the correct resource on the server.
  3. Check the access permissions: a 405 Method Not Allowed error may occur if the client does not have the necessary permissions to perform the requested action on the resource. Check the access control mechanisms on the server and ensure that the client has the required permissions.
  4. Check the server configuration: the server may be configured to block certain HTTP methods for certain resources. Check the server configuration to make sure that the desired method is allowed for the resource in question. If you have access to the server configuration, you can adjust it accordingly.
  5. Check firewalls and proxies: It is possible that firewalls or proxies are restricting HTTP traffic and causing the 405 Method Not Allowed error. Make sure firewalls or proxies are configured correctly and allow the required HTTP methods for communication.
  6. Update the software you are using: sometimes outdated or buggy versions of software (such as web browsers or API clients) can cause errors. Update the software you are using to the latest stable version and check if the problem persists.
  7. Consult documentation or support: If none of the above solutions solve the problem, you should consult the official documentation of the server or API. There you may find specific information or further troubleshooting steps. If needed, you can also contact the technical support of the server or API for further assistance.

Note that the solution to the 405 Method Not Allowed error may depend on the specific environment and context.

.

How to create a custom error page for the 405 status code

Creating your own 405 Method Not Allowed error page is relatively easy with the web server "Apache" as well as with the web server "NGINX".

Apache Webserver

The web server "Apache" is one of the most popular web servers on the Internet. To create an own 405 Method Not Allowed error page in "Apache", the following change must be made in the following file.

File: .htaccess
ErrorDocument 405 /errors/405.html

NGINX Webserver

Similar to the web server "Apache", "NGINX" is also widely used on the Internet. To create your own 405 Method Not Allowed error page in "NGINX", the following change must be made in the following file.

File: sites-enabled/default
error_page 405 /405.html;
location = /405.html {
    root /usr/share/nginx/html;
    internal;
}

Browser compatibility of the 405 status code

Chrome no data
Edge no data
Firefox no data
Opera no data
Safari no data
Chrome Android no data
Firefox for Android no data
Opera Android no data
Safari on iOS no data
Internet no data
WebView Android no data

Constants in programming languages

HttpStatusCode.MethodNotAllowed
http.StatusMethodNotAllowed
Response::HTTP_METHOD_NOT_ALLOWED
httplib.METHOD_NOT_ALLOWED
http.client.METHOD_NOT_ALLOWED
http.HTTPStatus.METHOD_NOT_ALLOWED
:method_not_allowed

Sub status codes of the 405 status code

Sub status codes are purely technical, and should never be sent to the user. For example, if status code 405.1 is thrown, it may be logged, but status code 405 will be sent to the user.:
405.0 Method not allowed
HTTP IIS, Unofficial
Author: Tony Brüser
Author: Tony Brüser

Tony Brüser is an enthusiastic web developer with a penchant for HTTP status codes.

LinkedInGitHub