How to Create a Custom Smart 404 Script

If you're worried about finding a not so nice looking 404 page on your website you can quite easily add a custom 404 page to your site. This page will tell your visitors that the page they are trying to reach doesn't exist and it will also tell them where to find the content they are looking for. This article will teach you how to create a custom 404 script using just PHP and a couple of simple server commands, to pull in related pages along with giving an on site search option!

Steps

  1. Image titled Create a Custom Smart 404 Script Step 1
    1
    Make a PHP and CSS file. Name them something like smart404.php and smart404.css and place them in a folder (smart404) for easier editing on a server.
  2. Image titled Create a Custom Smart 404 Script Step 2
    2
    Add some simple HTML code to your PHP file.
  3. Image titled Create a Custom Smart 404 Script Step 3
    3
    Add the PHP code to display custom text depending on how a visitor reaches a 404 page on the site, here's the code for that part.
  4. Image titled Create a Custom Smart 404 Script Step 4
    4
    Try the following code to grab and post relevant pages on the 404 page from the keywords in the URL of that 404 page.
  5. Image titled Create a Custom Smart 404 Script Step 5
    5
    Add a search function to the custom 404 script which can be done in a number of ways either with Google search or a custom search engine.
  6. Image titled Create a Custom Smart 404 Script Step 6
    6
    Go to [www.google.com/cse] and create your own custom search (use the shiny option for a theme/layout if you wish to use my css correctly).
  7. Image titled Create a Custom Smart 404 Script Step 7
    7
    Find the line of code that says: "var customSearchControl = new google.search.CustomSearchControl('012869460898643755040:0jf7icffqma');" as you will need to change the code between () to you unique code.
  8. Image titled Create a Custom Smart 404 Script Step 8
    8
    Now you have all that here's what the code will look like to fully work with your site and custom smart 404:
  9. Image titled Create a Custom Smart 404 Script Step 9
    9
    You can download a fully functional copy of the script from [1]

Article Info

Categories: Website and Blog Creation