The HTTP 421 status code stands for "Misdirected Request". It is a client error response indicating that the server is not able to process the request because it was directed to the wrong server, usually due to misconfiguration.

When is HTTP 421 Used?

  • The 421 status code is returned when a request is sent to a server that is not able to handle the request, typically because the request is meant for a different server.
  • This often occurs in cases where a reverse proxy, load balancer, or virtual hosting setup is in place, but the request is sent to the wrong server, which is not configured to handle it.

Common Causes of HTTP 421 Errors

  • Incorrect routing: The request is sent to a server that is not set up to handle it, often because the hostname or URL was incorrect.
  • Misconfigured reverse proxy or load balancer: A reverse proxy or load balancer might incorrectly route the request to a server that is not responsible for the domain or service the request is intended for.
  • Host header issues: The Host header in the HTTP request may indicate the wrong domain, causing the request to be directed to the wrong server.

Example Scenarios

  • A request for a particular domain (e.g., example.com) is sent to a server that is set up for a different domain (e.g., different.com), causing the server to be unable to process the request.
  • A client sends a request to a server in a cluster of servers that isn't configured to handle that specific domain or service.

Example

Client Request (Incorrect Server Routing)

    
        GET / HTTP/1.1
        Host: example.com
    

(The client sends a request to example.com, but the request is routed to the wrong server, which is not configured to handle that domain.)

Server Response (421 Misdirected Request)

    
        HTTP/1.1 421 Misdirected Request
        Content-Type: application/json

        {
          "error": "The request was directed to the wrong server. Please check the server configuration or hostname."
        }
    

Best Practices for Handling HTTP 421

  • Check server configuration: Ensure that the server or reverse proxy is properly configured to handle requests for the correct domains or services.
  • Verify routing rules: In a load balancing or virtual hosting environment, verify that the routing rules are correctly defined to direct requests to the appropriate server.
  • Provide clear error messages: When returning a 421 response, provide an error message explaining that the request was misdirected and give guidance on what might have gone wrong (e.g., check DNS settings, Host header, or server routing configuration).

Summary

HTTP 421 is used when a request is sent to the wrong server that cannot process it. This can happen due to misconfiguration of routing systems, reverse proxies, or load balancers. Clients encountering this error should check the server or proxy settings, and ensure the request is sent to the correct server for the intended domain.