\n

404 - Page Not Found<\/h1>\n

The page you're looking for doesn't exist.<\/p>\n

Go back to the homepage<\/a><\/p>\n<\/body>\n<\/html><\/pre>

Save this file in your website's root directory (eg, \/var\/www\/html\/404.html<\/code> ) or any preferred location within your site structure. <\/p>\"How

2. Configure Apache Using .htaccess<\/code> (Recommended for Shared Hosting)<\/h3>

If you're using shared hosting or want to set this per-directory, use the .htaccess<\/code> file in your site's root:<\/p>

 ErrorDocument 404 \/404.html<\/pre>

Make sure the path ( \/404.html<\/code> ) is correct relative to the web root. You can also point to a dynamic page: <\/p>\"How

 ErrorDocument 404 \/error.php?code=404<\/pre>

? Ensure your .htaccess<\/code> is readable by Apache and that AllowOverride<\/code> is enabled in your Apache configuration for the directory.<\/p><\/blockquote>

3. Set It in Apache Virtual Host (Best for VPS or Dedicated Servers)<\/h3>

If you have access to the server configuration, it's better to define it in the virtual host block.<\/p>

Edit your site's config file (eg, \/etc\/apache2\/sites-available\/000-default.conf<\/code> or similar):<\/p>

 \n    ServerName yourdomain.com\n    DocumentRoot \/var\/www\/html\n\n    ErrorDocument 404 \/404.html\n\n    # Other directives...\n<\/VirtualHost><\/pre>

After making changes, restart Apache:<\/p>

 sudo systemctl restart apache2<\/pre>

or on some systems:<\/p>

 sudo service apache2 reload<\/pre>

4. Test the Custom 404 Page<\/h3>

To verify it works, navigate to a non-existent URL on your site:<\/p>

 http:\/\/yoursite.com\/this-page-does-not-exist<\/pre>

You should see your custom 404 page instead of the default Apache error.<\/p>\n

A Few Tips<\/h3>\n