How To Create A Custom 404 Page



So when they built their 404 page, they used their widely known branding to create a unique and amusing 404 page. They used both text and image to show that the user is at the end of the trail. NPR’s 404 page looks ordinary enough at first glance. Drupal makes it easy to add the custom 403 and 404 pages. Note of caution Because this approach uses nodes (i.e. Individual pieces of content), the 403 and 404 pages will show in search results.

404 is an error that is displayed when the server fails to locate the page or file that the user requests.

It essentially forms a dead end for the visitor, since they can do nothing else but return to the homepage or go to a different site. Thus, an unfriendly and blunt 404 page may result in visitors being dissatisfied or annoyed with the site’s user interface and cause them to swiftly exit your site.

The LCN 404 page

How

On the other hand, a friendly and engaging 404 page will help prevent your visitor exiting your page and encourage them to check out other sections of the site, effectively decreasing bounce rates.

There are many of advantages to be had by creating a custom 404 page for the website, some of which include:

  • Help visitors find their way around
    Include a set of links to popular pages on your site and try to tempt a lost visitor to continue browsing. Otherwise, they’ll have to go all the way back to the homepage and rummage through the site’s contents to find what they are looking for (if they stay at all).
  • Make the error page user-friendly
    By making the 404 page friendly and welcoming, you can ease your visitors frustration, rather than increasing it with a blunt “Error” pasted across the page.
  • Leverage on SEO benefits
    Customise the error page to make it resemble the other pages of the site. Provide a site search option or a site map link. This way you encourage your user to keep browsing.
  • Get new links
    Difficult to achieve, but possible. If you create a truly unique, engaging, amusing 404 page, visitors will want to tell the world. This can be a great source of new links. More on truly excellent 404 pages at the end of this article…

Creating a custom 404 page is fairly easy, but does require a little coding and design.

You begin by creating a new webpage on your site (either on your CMS such as WordPress, or a regular HTML page/PHP script).

If you’re reading this and haven’t already got hosting for your website, we can help with that. Check out our range of web hosting plans here.

Now, before we go about creating your custom 404 error page, there are some things that you need to keep in mind:

  • Try to keep it light-hearted
    Remember, one of the primary reasons why we’re creating a custom 404 page is to replace the blunt and annoying “page cannot be displayed” message with something which is less likely to chase away visitors.
  • Include a search box
    Also ensure to place a search box at a prominent location in your custom 404 page. This enables the lost visitor to search for what they are looking for in the site.
  • Include important links
    You know that a 404 error page is like a dead end. Now your task is to offer alternative courses of action to the visitor. You can do this by providing links to important and popular sections of the site like recent posts, subscriptions, contact us, etc.
  • Do not make your visitor feel stupid
    Whilst your visitor may have entered an incorrect link, do not blame the visitor for the error. Instead, explain the problem in a casual and light-hearted way. Besides, perhaps a link on your website sent your visitor there in the first place!

Creating a custom 404 page

As mentioned, creating a custom 404 page does require a little coding and design, and unless you have some experience with coding web pages, it’s may be best left to your web designer.

The process starts by designing a standard web page, and including all the elements you require for your 404 page.

Remember to include a light-hearted message explaining why a visitor has landed on this page, a search box so they can find what they are looking for, and perhaps a sitemap so the user can choose to navigate elsewhere.

What you name your 404 page is important. In this case, we’ll name it “404.html“. Then upload your page to the root directory of your server / web space.

The process is a little different if use WordPress. There are plugins available that make things even easier, without the need to touch any code.

For full details on 404 pages for WordPress, check out this complete guide over at Elegant Themes.

Configure the server to redirect to your custom 404 page

This probably sounds a bit more complicated than it is. What we want to do is ensure that if anyone ever visits a page (URL) on your website that doesn’t exist, the server will always display back your helpful 404 page.

The overwhelming majority of web servers use Apache software, so we’ll run through the apache method for redirection.

How To Create A Custom 404 Page Wordpress

To start, you’ll need to either find your websites .htaccess file, or create one.

How to create a custom 404 page in django

Apache web servers use “.htaccess” file to let users customise their web server configurations at the directory level. For more details on .htaccess, including how to find it or create one, check out our guide here.

.htaccess file in root directory of a WordPress install

.htaccess can have many functions; these are the steps to create your 404 page.

Step 1: Creating or finding the “.htaccess” file: To find your .htaccess file, just take a look in the root directory for your website using your usual FTP client. You should see it in there. If you need to create one, its simple. Just open up a text editor, such as Notepad, and name the file “.htaccess”.

Step 2: Add the following text to the .htaccess file: “ErrorDocument 404 /404.html”. This line names your 404 error page as ‘404.html’ and locates it in your web site’s root directory.


Add this code to your .htaccess file

Step 3: Save file and get it uploaded into your server’s root directory.

Step 4: Check out if things are working fine by opening the web browser and navigating to www.yourdomain.com/asdf (a random page that does not exist).

What not to do:

While designing the custom 404 error page, there are some things that you should avoid.

  • Never redirect the 404 errors to a different web site. Remember the goal of the custom 404 is to improve your visitors experience. Sending them to a totally different website will frustrate them.
  • Do not redirect 404 errors to the website’s home page. This will only confuse your visitor. This is because they clicked on one link and found themselves back on the homepage for no reason. Bad move.
  • And perhaps most importantly; don’t blame your visitor!

Brilliant 404 pages

404 pages don’t have to be boring. Some web designers have used 404 pages as an opportunity to create something fun and engaging for their lost visitors.

As mentioned earlier in this article, some of the very best 404 pages even attract backlinks of their own! Let’s take a look at some of our favourites.

Click on the website title to visit the 404 page.

Help Good Dog Design find their lost dog!

IMDBs 404 page greets you with a selection of relevant movie quotes.

The guys at Romainbrasier let you forget your 404 woes by saving 404 Lemmings!

Magnt have come up with an amusing Venn diagram to explain why you might have found their 404 page.

Modcloth present a funny image, but also offer a variety of strong call-to-action buttons to get their visitor back on-track, and buying again!

Your Say!

Have you created your own custom 404 page? We’d love to see it.

As a visitor what do you look for in a 404 page? And what makes you bounce from the page immediately?

Introduction: Custom 404 Error Page in PHP

Every website gets the occasional, frustrating Error 404: Not Found. And if you have your own website, you may wish to customize these error pages. Thankfully, it's not that hard to do. Your error pages may be of any extension you want. Usually, they are written in SHTML. But SHTML isn't very dynamic in terms of what can be done with it. So I went over to PHP for my error pages. The coding wasn't hard either. So let's begin.

Step 1: Requirements

If you have a website, your hosing server should have PHP installed. If not, ask your server's admin if they would be kind enough to install it. If you are just screwing around wasting time, you need some type of emulator. If you're on Windows, use easyPHP for this. If you're on Linux and can spare the resources, get: apache2 and php (for Ubuntu, sudo apt-get install apache2 php). If you're on mac, I have no idea what you can use.
Once you meet these requirements, go to the next step.

Step 2: .htaccess

How to create a custom 404 page
As stated on the cover page, your custom error page(s) can have any extension you want. But you can't use it if your server isn't told to use it. This is where .htaccess comes in. .htaccess is a file named, well, '.htaccess'. This file can be used to configure your site to certain degrees. What we will do is go ahead and point the 404 error to 404.php (which, ironically, doesn't exist yet). This will be a hidden file (every file that begins with a dot is a hidden file). So make sure you can view hidden files. In this file, write the following code and save it:
And while you're at it, if you feel like it:
404

Step 3: 404.php

And the actual error page. I'm going to ignore the whole 'let's follow standards' thing I usually do. The reason I chose PHP for the error page is because you can figure out the source of the error to an extent; you can see if the missing page was typed in the address bar, if it was a link on your site, or if it was a link on a different site. This is achieved by parsing a server variable. You can also parse a couple other server variables and see exactly what was put into the address bar. For this ible, we will only grab the requested page and the referrer, if any.
The line above will tell the visitor that the page they want, along with the page's path (preceded with a slash), does not exist. It's helpful to tell the specific page because the hyperlink they followed, if they followed, may not reflect the page's path. The next code will grab if there was a referrer and who it was.
On my site, I told the user one of three things to do as per the code. If the referrer was my site, email me and let me know. If the referrer was on a different site, email them and let them know. If they types randomly in the address bar, stop doing that.

Step 4: Testing

First, go to your site like normal. It should show up normally. To test if your .htaccess is being read, insert random junk anywhere inside it and save it. Reloading the page should give a 500 error. If not, make sure your site is set up to use .htaccess files (I just had to edit my server's config files to get it to work). If it still don't work, try deleting all the blank spaces and reinserting them.
Else, undo the junk and re-save it. Now try to visit a non-existent page. You should see your 404 page. Add a few dead links on your site and try to follow them. You should end up with the same 404 page but with different content. Add a dead link to another website and the 404 page will have different content.

Step 5: Files

Here are the files used in this ible. Edit as desired/required.

1 Person Made This Project!

Recommendations

How To Create A Custom 404 Page In Wordpress

2 69
BEAM Solar Powered Pummer (Heart Shaped PCB) in Art
Digital Measuring Roller Using Microbit & Tinkercad in Tools
Pocket Dice! Electronic Dice for Liars Dice and More in Electronics

How To Create A Custom 404 Error Page Php

  • Make it Glow Contest

  • First Time Author Contest

  • PCB Challenge