Create a custom 404 Error Page in php using htaccess


How to Create a custom 404 Error Page in PHP using htaccess

In this tutorial, you will learn how to create a 404 error page in php using htaccess.

We will be using this 404 Error Page in websites. When the requested url or page is not found, we will display the 404 Error Page, which we will be doing in php using htaccess file. So, Let's get started:

We will be using Bootstrap v5 to design the 404 Error Page.

Step 1: Create a file named 404.php and paste the below given design:

<!DOCTYPE html>
<html lang="en">
    <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 href="" rel="stylesheet" >

    <div class="py-5">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-md-7">
                    <div class="card card-body text-center">
                        <h4>Page Not Found!</h4>

    <script src=""></script>
    <script src=""></script>


Step 2: Create dot . htaccess file in your root folder and paste the below code:

RewriteEngine On

ErrorDocument 404

and now, lets try to access wrong page or url as

your will be redirected to your 404.php page.

Thanks for reading.

© Copyright - 2018 - 2023 | All rights reserved at Funda of Web IT