Htaccess: Site error documents: Difference between revisions
Punctuation and grammatical changes; some clarification. |
m Folder to Directory. |
||
(2 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
<div style="padding:0;margin:0; border-bottom:3px inset #000000"> | <div style="padding:0;margin:0; border-bottom:3px inset #000000"> | ||
{| | {| | ||
.htaccess: | .htaccess: | ||
[[Htaccess: Introduction | Introduction]] | | [[Htaccess: Introduction | Introduction]] | | ||
Line 20: | Line 20: | ||
'''Site error documents''' | '''Site error documents''' | ||
Apache provides some bland error documents | Apache provides some bland error documents, but you are not restricted to using just these. You can provide your own and match them to your site's look. | ||
== What errors produce what == | == What errors produce what == | ||
Line 63: | Line 63: | ||
== How to create customised error documents == | == How to create customised error documents == | ||
Create a new | Create a new Directory in your root directory (www) and name it '''errors'''. This will contain all the custom error pages you wish to display. For example, '''not_found.html''' will be displayed when a page cannot be found on your web site. | ||
Now open the root .htaccess file (the one in your root | Now open the root .htaccess file (the one in your root directory www) and add the following line: | ||
'''ErrorDocument 404 /errors/not_found.html''' | '''ErrorDocument 404 /errors/not_found.html''' | ||
Save the file. The command '''ErrorDocument 404''' will forward a user to '''<root | Save the file. The command '''ErrorDocument 404''' will forward a user to the '''<root>/errors/not_found.html''' file when ever Apache produces the error 404. | ||
'''''Note 1'':''' The files and | '''''Note 1'':''' The files and directory can be named anything you like.<br> | ||
'''''Note 2'':''' You can use a full URL (as oppose to a virtual path) to your error file; for example: <nowiki>http://yoursite.com/errors/not_found.html</nowiki> | '''''Note 2'':''' You can use a full URL (as oppose to a virtual path) to your error file; for example: <nowiki>http://yoursite.com/errors/not_found.html</nowiki> | ||
Line 98: | Line 98: | ||
|-style="background:#f9f9f9" | |-style="background:#f9f9f9" | ||
| | | | ||
# Create a new | # Create a new directory in www named '''errors'''. | ||
# In this | # In this directory create a file named '''not_found.html''' | ||
# Add the code shown on the right | # Add the code shown on the right. | ||
# Save the file | # Save the file. | ||
| | | | ||
<pre style="padding:4px;margin:0;border:none"> | <pre style="padding:4px;margin:0;border:none"> | ||
Line 119: | Line 119: | ||
|-style="background:#f9f9f9" | |-style="background:#f9f9f9" | ||
| | | | ||
# Navigate to the root | # Navigate to the root directory '''www'''. | ||
# Open the '''.htaccess''' file | # Open the '''.htaccess''' file. | ||
# Add the command shown on the right last line. | # Add the command shown on the right last line. | ||
# Save the file | # Save the file. | ||
| | | | ||
<pre style="padding:4px;margin:0;border:none"> | <pre style="padding:4px;margin:0;border:none"> | ||
# This file provides security | # This file provides security for the server, limiting access to the localhost only. | ||
# Comment to deactivate. | # Comment to deactivate. | ||
Line 133: | Line 133: | ||
Allow from ::1 | Allow from ::1 | ||
# To allow execution of cgi scripts in this directory, uncomment next two lines. | # To allow execution of cgi scripts in this directory, uncomment the next two lines. | ||
AddHandler cgi-script .pl .cgi | AddHandler cgi-script .pl .cgi | ||
Line 152: | Line 152: | ||
=== Testing === | === Testing === | ||
:# | :# (Re)start the server. | ||
:# In the browser address bar, type '''<nowiki>http:/localhost/fred.html</nowiki>''' or some other file that does not exist. | :# In the browser address bar, type '''<nowiki>http:/localhost/fred.html</nowiki>''' or some other file that does not exist. | ||
:# Apache will generate the error code 404 and redirect to your not_found.html page | :# Apache will generate the error code 404 and redirect to your not_found.html page | ||
Experiment with the ErrorDocument command and create a few pages. | Experiment with the ErrorDocument command and create a few other pages. | ||
---- | ---- | ||
[[Category: | [[Category: Apache Configuration]] | ||