Handle 404, 500, and 301 Apache Errors With .htaccess file

Apache Server
Apache Server

If A 404 Error happen in your web site it will show a not available page with no links. You can escape from this situation very easly. The solution is surprisingly simple. Use your .htaccess file simply put a line

ErrorDocument 404 /index.php

in the file. The error redirected to your home page. Problem solved.

Interestingly enough you can also redirect to a specific page such as a custom 404 error page that you code up in php . Just replace the “/errors/badrequest.html” part with “/myCustom404ErrorPage.php” and you’ll be fine.

Please find below a pretty complete list of server returned errors.

Apache Server Error Codes

Successful Client Requests

  • 200 OK
  • 201 Created
  • 202 Accepted
  • 203 Non-Authorative Information
  • 204 No Content
  • 205 Reset Content
  • 206 Partial Content

Client Request Redirected

  • 300 Multiple Choices
  • 301 Moved Permanently
  • 302 Moved Temporarily
  • 303 See Other
  • 304 Not Modified
  • 305 Use Proxy

Client Request Errors

  • 400 Bad Request
  • 401 Authorization Required
  • 402 Payment Required (not used yet)
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowed
  • 406 Not Acceptable (encoding)
  • 407 Proxy Authentication Required
  • 408 Request Timed Out
  • 409 Conflicting Request
  • 410 Gone
  • 411 Content Length Required
  • 412 Precondition Failed
  • 413 Request Entity Too Long
  • 414 Request URI Too Long
  • 415 Unsupported Media Type

Server Errors

  • 500 Internal Server Error
  • 501 Not Implemented
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
  • 505 HTTP Version Not Supported

Leave a Reply