Apache – Custom 404 pages

The standard 404 (Page not found) is enough for telling someone the page they are looking for is not there. However, you can use that 404 traffic to share funny pages or redirect them to your main page. Or you can promote product, adverts and such. Whatever you want to use your 404 traffic for. Here is how you do it.

Ssh into your web server, if your not local, and navigate to the root folder of your website.

Example: /var/www/example.com/


Create a .htaccess file if you don’t have one from before. And add this to your .htaccess file.

ErrorDocument 404 /404.html

The above line says if a 404 error, go to 404.html. And this example assumes the 404.html file is located in the website root folder.
Example of a 404.html file:

[sourcecode language=”html”]
<body bgcolor=”#000000″>
<font color=”white”>
<h1>I’m terrible sorry</h1><br>
<img src=”pirate-flag.png” alt=”404″>
<h1>A pirate stole this page!</h1></font></center>

The pirate flag can be downloaded here: Pirate flag

Note: If you still get the normal 404 from Apache, you have not AllowOverride enabled. Here is how to enable it.
vim /etc/apache2/sites-available/default

Locate the following section:
[sourcecode language=”html”]
<Directory> /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all

And change the AllowOverride None to:
AllowOverride all

Then you need to restart apache to make the changes into effect.
service apache2 restart

Happy redirecting!

About Author

Related Posts

wordpress page not found

WordPress page not found after changing permalinks

Permalinks are a critical aspect of a WordPress website’s structure, providing user-friendly URLs that enhance both SEO and user experience. However, occasionally, WordPress users encounter permalink issues…

install php ziparchive

Install PHP ZipArchive for Debian

PHP ZipArchive is a file archive for zip compression used by many web applications and plugins. How to install PHP ZipArchive for Debian is an easy task….

debian apache log

Debian Apache log file analyser

Debian Apache log files contain tons of useful information about your web server and websites. Here I will show how to install GoAccess to help you get…

ssh upload www

ssh upload www folder

ssh upload www Ssh upload www. Note this article is for Debian based Linux distributions. Several web designing tools offer ssh or sftp uploads to your site…

Apache – Disable libwww-perl access

libwww-perl access blocking Libwww-perl access is often used by botnets and other nasty softwares to scan your site for vulnerabilities. Luckily it is quite easy to block…

Apache – Disable directory browsing in Debian

Disable directory browsing If you have directory browsing enabled, which it is by default, your users can browse the directories on your web server. This is not…

Leave a Reply