glFusion Wiki

Site Tools


Creating a Custom 404 (Not Found) Page

A custom 404 page lets you provide a user-friendly page to your visitors even when there is an error. Very few users, when presented with a 404, will do more beyond click back to get out of the mistake. A custom 404 page is a good opportunity to keep them on your site and do more to redirect them to the content you provide.

Configuring the Web Server

Before you can leverage glFusion's 404 - Page Not Found handling, you must first setup your web server to redirect to a glFusion page when it encounters a 404 - Page Not Found error. glFusion provides a custom Page Not Found handler in the public_html/404.php file. Follow the steps below to configure your web server to use glFusion's 404.php page not found handler.

Apache Web Server

To edit the 404 page, open up or create the site's .htaccess file. You can create it in a text editor and upload it to your site via the FTP server. Keep in mind that the name of the file has to be simply .htaccess.

Add the following line to the file:

ErrorDocument 404 /404.php

Save and Exit.

Keep in mind that the Apache looks for the 404 page located within the site's server root. Meaning that if you place the new error page in a deeper subdirectory, you need to include that in the line, making into something like this:

ErrorDocument 404 /path_to_sites_public_files/404.php

IIS 7.0+

Step 1: Open the Internet Services Manager.

Step 2: Double-click the Error Pages icon in the IIS section.

Step 3: Select “Edit Feature Settings,” which will display its dialog box. “Edit Features Settings” is located underneath the “Actions” tab.

Step 4: Go to the “Custom error pages” selection.

Step 5: Define the 404 error code. If someone has previously configured a custom 404 error page, select it and edit it. If this is the first time a custom 404 error page is being configured, click on the “Add” link under “Actions.” From there, you can type in “404” as the status code, and select “Insert content from static file into the error response” and put in the path to your custom 404 file.

Step 6: Define the individual error page by adding a custom page for the HTTP 404 error. Then, select “OK.”


Now, we just need to tell Nginx that it should be utilizing these pages whenever the correct error conditions occur. Open the server block file in the /etc/nginx/sites-enabled directory that you wish to configure. We will use the default server block file called default, but you should adjust your own server blocks if you're using a non-default file:

sudo nano /etc/nginx/sites-enabled/default

We can now point Nginx to our custom error page.

Use the error_page directive so that when a 404 error occurs (when a requested file is not found), the custom page you created is served. We will create a location block for the file, where we are able to ensure that the root matches our file system location and that the file is only accessible through internal Nginx redirects (not requestable directly by clients):

server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
      . . .
      error_page 404 /404.php;
      location = /404.php {
              root /usr/share/nginx/html;

You will need to restart nginx after making the above changes.

Customizing glFusion's 404 Page (glFusion v1.6.5+)

Out of the box, glFusion provides a generic 404 error page that informs the user the content could not be found and offers them links to your home page and the search page. You can customize this page to provide additional information or better visuals.

Custom 404 Static Page

You can create a static page named _404, if this page exists and is enabled, glFusion will use this page whenever a 404 error is encountered.

By utilizing a static page, you can now completely customize how the 404 page will look. You can set it up to match your site's look and feel, use custom images, customize the text, etc. Below is a very simple sample of a custom _404 page:

<p style="text-align: center;"><strong><span style="font-size:72px;">404</span></strong></p>
<p style="text-align: center;">&nbsp;</p>
<p style="text-align: center;"><strong><span style="font-size: 36px;">Page Not Found</span></strong></p>
<p style="text-align: center;">&nbsp;</p>
<p style="text-align: center;"><span style="font-size:24px;">We were unable to locate the page you were requesting.</span></p>
<p style="text-align: center;">&nbsp;</p>
<p style="text-align: center;"><span style="font-size:24px;">You might want to try our <a href="/search.php">Search Page</a> or <a href="/index.php">Home Page</a></span></p>
<p style="text-align: center;">&nbsp;</p>
glfusion/styling/custom_404.txt · Last modified: 2017/01/17 20:58 (external edit)