CodeIgniter3

24. [CodeIgniter3] 404 Page not found 페이지 만들기

drizzle0925 2022. 1. 7. 14:48
728x90

페이지를 찾을 수 없을 때 "404 페이지를 찾을 수 없음" 오류 페이지를 표시합니다.

"404 페이지를 찾을수 없음"은 사용자가 웹 사이트에 액세스 하는 동안 직면하는 가장 일반적인 오류입니다.

 

이번 포스팅에서는 CodeIgniter에서 완전히 사용자 정의된 404 오류 페이지를 만드는 방법에 대해서 정리했습니다.

웹 응용 프로그램을 사용자 친화적으로 만들고 사용자가 웹 사이트로 돌아갈 수 있도록 도와줍니다.

사용자가 끊어진 링크나 존재하지 않는 URL을 클릭하면 화면에 오류 메시지가 나타납니다.

이러한 오류 메시지는 관리자가 삭제한 페이지에 접속하거나 삭제된 페이지를 링크를 타고 이동할 때 주로 발생합니다.

 

주로 끊어진 링크는 404(페이지를 찾을수 없음) 오류 페이지를 표시하는 역할을 합니다.

CodeIgniter에서는 필요에 따라 404 오류 페이지를 쉽게 사용자가 설정할 수 있습니다.

이를 위해서는 404 오류 페이지의 HTML을 생성해야 합니다.

 

application/views/errors/html/error_404.php 파일을 열고 아래 코드로 수정합니다.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$ci = new CI_Controller();
$ci =& get_instance();
$ci->load->helper('url');
?>
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>404 Page Not Found</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <link href='http://fonts.googleapis.com/css?family=Amarante' rel='stylesheet' type='text/css'>
    <style type="text/css">
        body{
            background:url('<?php echo base_url();?>assets/front/images/404.png');
            margin:0;
            background-repeat:no-repeat;
        }
    </style>
</head>
<body>
    <div class="container" style="margin-top:500px;margin-left:350px;">
        <p><a class="btn btn-warning" href="<?php echo base_url(); ?>">Go Back to Home</a></p>
    </div>
</body>
</html>

 

 

asset/front/images/404.png 파일을 저장합니다.

 

아래 주소로 이동합니다.

localhost/abc/

 

Github : https://github.com/jun0925/study/commit/1c1953b70efec60ecbedbd3fb0882e68c655d433

728x90