16

I want to customise the 404 page of my Apache Webserver on Ubuntu to something other than the general:

Not Found

The requested URL /***** was not found on this server.
______________________________________________________

Apache/*.*.** (Ubuntu) Server at **** Port 80

How can this be accomplished?

1

5 Answers 5

20

I found the answer myself.

You have to edit the file /etc/apache2/conf.d/localized-error-pages

sudoedit /etc/apache2/conf.d/localized-error-pages

You can enter plaintext or link to a script or html

6
<VirtualHost 192.168.0.1:80>
    ServerAdmin [email protected]
    ServerName host.ru
    ServerAlias www.host.ru
    DocumentRoot /home/WebServer/www/host.ru/public_html/
    ErrorLog /home/WebServer/www/host.ru/logs/error.log
    CustomLog /home/WebServer/www/hostu/logs/access.log combined


    Alias /error_html/ "/home/WebServer/www/host/error_html/"
    <Directory "/home/WebServer/www/host.ru/error_html">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en cs de es fr it nl sv pt-br ro
        ForceLanguagePriority Prefer Fallback
    </Directory>
    ErrorDocument 404 /error_html/HTTP_NOT_FOUND.html
</VirtualHost>
3

Here is a solution. Hope it helps.

DEMO

Go to your site's folder.

Create a file named .htaccess (just .htaccess no name only file extension).

Open the file and add the line.

ErrorDocument 404 /pathtofile

Replace /pathtofile with your 404 page file name which should be situated in the same folder as the file .htaccess . The custom 404 file can be in PHP or HTML. You can also add HTML to it like this:

ErrorDocument 404 '<h1>404 Not Found</h1>'

You don't have to reload Apache Server ! It's finished. Test it out.

Source - Subin's Blog

2
  • 1
    This would require "AllowOverride" config in apache to be on, which is not the default in ubuntu.
    – Nemo
    Jun 19, 2013 at 10:26
  • This worked for me
    – Simon
    Jun 19, 2013 at 11:36
0

One kind of 404 customization (not yet covered here) is redirecting the 404 page in VPS Ubuntu to a separate page, such as the site's home page.

To do this, make a file called .htaccess in the web root and put this line in it:

ErrorDocument 404 http://www.yoursite.com

Then save the file.

This will make the 404 page redirect to the specified URL.

0

AFAIK you can not customize default error messages of Apache 2.4 in any easy way because those messages are inside the apache2 executable.

However, you can override them using "ErrorDocument" directives which can be used also in apache2.conf.

An even better way could be using Include in apache2.conf and collect overridden messages in one separate file.

Please also see the Apache 2.4 documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .