132 lines
6.2 KiB
HTML
132 lines
6.2 KiB
HTML
<h1>Adding custom error pages to your SDF website</h1>
|
|
<hr />
|
|
|
|
<h2>Contents</h2>
|
|
<ul>
|
|
<li><a href="#intro">Introduction</a></li>
|
|
<li><a href="#why">Why create a custom error page?</a></li>
|
|
<li><a href="#how">How to implement your custom error page</a></li>
|
|
</ul>
|
|
<br />
|
|
|
|
<h2><a id="intro" />Introduction</h2>
|
|
<p>The HTTP protocol, which is used to retrieve documents (usually web
|
|
pages) from the internet for display in a web browser, provides a number of
|
|
<a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">
|
|
standard error codes</a> to indicate conditions or status relative to
|
|
the process. The most widely known of these is the notorious code 404
|
|
- "File not found." This error may occur for a number of reasons,
|
|
but most commonly it indicates a broken link. Perhaps there is a
|
|
typographical error in your html, or maybe the document was moved to
|
|
a new location without the needed changes made to the referring
|
|
link. What happens at this point is that the web browser asking for
|
|
the missing document receives a special error message web page
|
|
instead. This page is usually provided by the server, but may in
|
|
some instances be generated by the browser. The error page may be
|
|
rather generic, or it may be customized for the originating site.
|
|
</p>
|
|
|
|
<h2><a id="why" /></a>Why create a custom error page?</h2>
|
|
<p>Good question! Generally, the error pages provided by the server are
|
|
adequate. On that basis, changing them isn't really required.
|
|
However, such messages also tend to be dull and often rather cryptic.
|
|
So, you might decide to create customized error messages for a
|
|
variety of reasons. <br />
|
|
For example:
|
|
</p>
|
|
<ul>
|
|
<li>You may wish to create an error page which retains the look and
|
|
feel of your own site. This may increase the comfort level of your
|
|
viewers, since they won't necessarily feel like they have suddenly
|
|
been whisked away from what they were viewing into some mysterious
|
|
la-la land they'll have to crawl back from. Here is an example:
|
|
<a href="http://www.google.com/qrstuvwxyz">Google's 404 page</a>
|
|
</li>
|
|
<li>Since the error may have been caused by a fault in your site,
|
|
you might want to direct the viewer to contact you about it, so that
|
|
you can fix the problem.
|
|
</li>
|
|
<li>You may want to provide the viewer with additional information
|
|
designed to help them resolve the issue themselves. This is useful
|
|
if the problem is caused not by your site but by some mistake the
|
|
user made in entering the URL, for example:
|
|
<a href="http://www.microsoft.com/qrstuvwxyz">Here</a> is an example
|
|
of that.
|
|
</li>
|
|
<li>And let's face it - most error pages are pretty dull. The 404
|
|
page in particular can be frustrating. So much so, in fact, that
|
|
people have even written spiteful
|
|
<a href="http://www.ovff.org/pegasus/songs/404-not-found.html">songs</a>
|
|
about it!
|
|
</li>
|
|
</ul>
|
|
|
|
<h2><a id="how" />How to implement your custom error page</h2>
|
|
<p>Now that you've decided you want to create a custom error page, you
|
|
probably want to know how to do it. In fact, on SDF this turns out to be
|
|
fairly easy. There are two basic steps involved:
|
|
</p>
|
|
<ol>
|
|
<li>Create the custom error pages that you want displayed.</li>
|
|
<li>Create (or modify) the file <code>.htaccess</code> in the root of
|
|
your html directory structure.</li>
|
|
</ol>
|
|
<p>Creating the custom error page itself is just like creating any other
|
|
web page. Thus, it is somewhat beyond the scope of this article, as
|
|
really you can do what you like. But if you are short of ideas, check
|
|
out <a href="http://www.lightecho.net/404page/404_fame.html">this</a> site.
|
|
</p>
|
|
<p>The key to making your custom error page work is in correctly
|
|
informing the Apache web server that you have created a custom document
|
|
and precisely indicating where that document is located. This is
|
|
accomplished through an entry in the <code>.htaccess</code> file.
|
|
</p>
|
|
<p>For the purposes of this discussion, we'll assume you already have
|
|
your website set up. The root folder of your html directory structure
|
|
is where you need to create <code>.htaccess,</code> or modify it if it
|
|
already exists. If you are logged into an SDF shell account, you can
|
|
generally get to this folder by entering this command:
|
|
</p>
|
|
<code>cd ~/html</code>
|
|
<p>If you are using SDF's vhost services, you need to change to the
|
|
directory for the website you are updating - it's probably a
|
|
subdirectory of the html directory. Once in the folder, you can create
|
|
or edit the file by entering:
|
|
</p>
|
|
<code>pico .htaccess</code>
|
|
<p>Of course, while pico is the editor I like to use, you have your
|
|
choice of several others and should feel free to use the one you like.
|
|
You can also create or edit the file on your own system and upload
|
|
it to SDF just as you would any other web document.
|
|
</p>
|
|
<p>With the Apache web server, as used on SDF, <code>.htaccess</code>
|
|
provides "a way to make configuration changes on a per-directory
|
|
basis." The complete use of this file is way beyond the scope of this
|
|
article, but more information is available
|
|
<a href="http://httpd.apache.org/docs/1.3/howto/htaccess.html">here</a>.
|
|
</p>
|
|
<p>In our scenario, you are probably creating a new file, so you'll be
|
|
starting with a blank slate. You will need to create one line for each
|
|
error page that you define. To indicate to the server that you want to
|
|
use your own code 404 message, you'll need to add a line that is similar
|
|
to this one:
|
|
</p>
|
|
<code>ErrorDocument 404 /404.html</code>
|
|
<p><code>ErrorDocument</code> indicates that you are defining your own,
|
|
<code>404</code> is the error code you are taking responsibility for,
|
|
and <code>/404.html</code> is the name and location of your custom error
|
|
document. Please note that the "/" in front of the file name is
|
|
necessary on SDF for the relative path to work. And if you place the
|
|
document in a subdirectory off your html root, you need to indcate that
|
|
path in <code>.htaccess</code>, If you are creating custom pages for
|
|
additional codes, simply add the appropriate lines in
|
|
<code>.htaccess</code>
|
|
</p>
|
|
<p>After making your changes, it may be a good idea to reset
|
|
the permissions on your website by entering the command:
|
|
</p>
|
|
<code>mkhomepg -p</code>
|
|
<p>And that is pretty much all there is to it! </p>
|
|
<hr />
|
|
$Id: errorpage.html,v 1.5 2017/05/25 02:25:27 bradmac Exp $
|