htaccess error document

htaccess error document

  • Thông thường khi trang web bị lỗi, sẽ xuất hiện câu thông báo mặc định không đẹp mắt, chúng ta có thể tạo một trang thông báo cho đẹp hơn, chuyên nghiệp hơn, sau đó khai báo sao cho các thông báo lỗi sẽ xuất hiện ở các trang báo lỗi tương ứng.

Cấu trúc htaccess

ErrorDocument mã_lỗi /đường_dẫn/trang_lỗi

Ví dụ:

ErrorDocument 404 /errors/404.php

Ví dụ về htaccess error document

  • Dưới đây là một vài khai báo với những lỗi thường gặp, trỏ tới trang lỗi tương ứng:
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
ErrorDocument 503 /errors/503.php

Nội dung trên có nghĩa là: khi người dùng truy cập vào trang web mà phát sinh lỗi ví dụ lỗi 404 (không tìm thấy trang) thì thay vì xuất hiện trang báo lỗi mặc định, .htaccess sẽ tự động điều hướng người dùng tới trang báo lỗi được tạo /errors/404.php

Lỗi từ phía Client

Lỗi Mô tả
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.

Lỗi từ phía Server

Lỗi Mô tả
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported.