User Tools

Site Tools


custom_error_pages_for_your_site

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
custom_error_pages_for_your_site [2024/09/01 20:24] – “.h hc9custom_error_pages_for_your_site [2024/09/02 23:19] (current) – ' hc9
Line 5: Line 5:
 ===== Why create a custom error page? ===== ===== Why create a custom error page? =====
  
-Good question! Generally, the error pages provided by the server are adequate. On that basis, changing them isnt 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.+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.
  
 For example: For example:
  
-  * 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 wont necessarily feel like they have suddenly been whisked away from what they were viewing into some mysterious la-la land theyll have to crawl back from. Here is an example: [[http://www.google.com/qrstuvwxyz|Googles 404 page]]+  * 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: [[http://www.google.com/qrstuvwxyz|Google's 404 page]]
   * 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.   * 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.
   * 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: [[http://www.microsoft.com/qrstuvwxyz|Here]] is an example of that.   * 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: [[http://www.microsoft.com/qrstuvwxyz|Here]] is an example of that.
-  * And lets 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 [[http://www.ovff.org/pegasus/songs/404-not-found.html|songs]] about it!+  * 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 [[http://www.ovff.org/pegasus/songs/404-not-found.html|songs]] about it!
  
 ===== How to implement your custom error page ===== ===== How to implement your custom error page =====
Line 25: Line 25:
 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 “.htaccess” file. 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 “.htaccess” file.
  
-For the purposes of this discussion, well assume you already have your website set up. The root folder of your html directory structure is where you need to create “.htaccess,” 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:+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 “.htaccess,” 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:
  
   cd ~/html   cd ~/html
  
-If you are using SDFs vhost services, you need to change to the directory for the website you are updating – its probably a subdirectory of the html directory. Once in the folder, you can create or edit the file by entering:+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:
  
   pico .htaccess   pico .htaccess
Line 37: Line 37:
 With the Apache web server, as used on SDF, “.htaccess” 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 [[http://httpd.apache.org/docs/current/howto/htaccess.html|here]]. With the Apache web server, as used on SDF, “.htaccess” 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 [[http://httpd.apache.org/docs/current/howto/htaccess.html|here]].
  
-In our scenario, you are probably creating a new file, so youll 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, youll need to add a line that is similar to this one:+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:
  
 <file sh .htaccess (vanity domain)> <file sh .htaccess (vanity domain)>
Line 43: Line 43:
 </file> </file>
  
-“ErrorDocument” indicates that you are defining your own, “404” is the error code you are taking responsibility for, and ''/404.html'' is the name and location of your custom error document. Please note that the “/” in front of the file name indicates that ''404.html'' may be found in the //www root directory of the site that the server is masquerading as// (a concept known as DOCUMENT_ROOT). Because the same physical computer might handle requests for multiple host names, the DOCUMENT_ROOT will be different for each SDF users vanity domain. Whenever the original request makes use of a vanity domain, say, //altego.freeshell.org//, the custom error document in the html subdirectory of //altego//s $HOME will be loaded with the syntax above.+“ErrorDocument” indicates that you are defining your own, “404” is the error code you are taking responsibility for, and ''/404.html'' is the name and location of your custom error document. Please note that the “/” in front of the file name indicates that ''404.html'' may be found in the //www root directory of the site that the server is masquerading as// (a concept known as DOCUMENT_ROOT). Because the same physical computer might handle requests for multiple host names, the DOCUMENT_ROOT will be different for each SDF user's vanity domain. Whenever the original request makes use of a vanity domain, say, //altego.freeshell.org//, the custom error document in the html subdirectory of //altego//'s $HOME will be loaded with the syntax above.
  
 ===== Changes needed if you use Apache's mod_userdir ===== ===== Changes needed if you use Apache's mod_userdir =====
  
-Some SDF users prefer to have their sites accessible via **tilde-style URLs**, like http://sdf.org/~altego . In this case the DOCUMENT_ROOT is no longer pointed at //altego//s html directory, but instead to the root html directory for SDF as a whole. Hence the location of the custom error page must be modified like so:+Some SDF users prefer to have their sites accessible via **tilde-style URLs**, like http://sdf.org/~altego . In this case the DOCUMENT_ROOT is no longer pointed at //altego//'s html directory, but instead to the root html directory for SDF as a whole. Hence the location of the custom error page must be modified like so:
  
 <file sh .htaccess (tilde-style URL)> <file sh .htaccess (tilde-style URL)>
custom_error_pages_for_your_site.1725222274.txt.gz · Last modified: 2024/09/01 20:24 by hc9