Edit Article

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!

Ad

EditSteps

  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.
    Ad
  2. Html.jpg
    2
    Add some simple HTML code to your PHP file.
  3. Smart 404 text.jpg
    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. Get suggested files.jpg
    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. 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. 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. 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. 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. Google custom search.jpg
    9
  10. 10
    == Fully Working Download ==
  11. 11
    You can download a fully functional copy of the script from [1]
    Ad

We could really use your help!

Can you tell us about
computers?
Yes
No
computers
how to dock a laptop
Can you tell us about
sabbaticals?
Yes
No
sabbaticals
how to plan a sabbatical
Can you tell us about
body tricks?
Yes
No
body tricks
how to make yourself cough
Can you tell us about
car stereos?
Yes
No
car stereos
how to install a car stereo
Thanks for helping! Please tell us everything you know about
...
Tell us everything you know here. Remember, more detail is better.
Tips
Provide Details.
Please be as detailed as possible in your explanation. Don't worry about formatting! We'll take care of it. For example:
Don't say: Eat more fats.
Do say: Add fats with some nutritional value to the foods you already eat. Try olive oil, butter, avocado, and mayonnaise.

Article Info

Categories: Website and Blog Creation

Thanks to all authors for creating a page that has been read 3,046 times.

Did this article help you?
Yes No

Become
an Author!

Write an Article