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”]
<html>
<body bgcolor=”#000000″>
<center>
<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>
</body>
</html>
[/sourcecode]
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
</directory>
[/sourcecode]
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!