KB 85: Difference between revisions
New page: ===How do I create a custom 404 message on my web site?=== Article:85 Created:2000-09-27 15:26:55 Categories: Web Publishing ====Question or Symptom==== When someone asks for a file... |
|||
| Line 33: | Line 33: | ||
exist. There are a couple of things to keep in mind about .htaccess files: | exist. There are a couple of things to keep in mind about .htaccess files: | ||
1. They are "recursive". The .htaccess file in your public_html directory | 1. They are "recursive". The .htaccess file in your public_html directory | ||
will affect all subdirectories. If you want to have different 404 messages | |||
for different parts of your site, you can put more .htaccess files in | |||
other subdirectories. The .htaccess files at lower levels in the directory | |||
tree will override the settings set at higher levels. | |||
2. If you already have .htaccess files to do access controls, just add the | 2. If you already have .htaccess files to do access controls, just add the | ||
ErrorDocument line near the top of the file. Make sure it is OUTSIDE | |||
and <LIMIT> statements in the file. | |||
3. The .htaccess file needs to be world-readable in order to work. If you're | 3. The .htaccess file needs to be world-readable in order to work. If you're | ||
working in Unix, "chmod 644 .htaccess" will set the appropriate | |||
permissions. If you're uploading the file with FTP, it will likely be | |||
set to the correct permissions. | |||
4. If you are using Front Page, this may not work. Front Page uses .htaccess | 4. If you are using Front Page, this may not work. Front Page uses .htaccess | ||
files as part of its setup and your change (adding an ErrorDocument line) | |||
may get deleted by Front Page sometime down the road. | |||
Latest revision as of 11:24, 4 June 2008
How do I create a custom 404 message on my web site?
Article:85 Created:2000-09-27 15:26:55 Categories: Web Publishing
Question or Symptom
When someone asks for a file that doesn't exist on my web site they get the generic SWCP 404 error page. Can I set up one specific to my web site and how do I do that?
Resolution
When a browser requests a file on your web site which does not exist, they receive a "404" error message. By default, they get a generic message which informs them that the file was not found. You can also specify a custom 404 error message to give the user additional information, inform them about a change in the web site structure, or even offer them a search page to help them find what they want.
To set up a custom 404 message for your site, create a file called ".htaccess" at the top level of your web site (usually in your public_html directory, but possibly in a subdirectory of public_html). The "." at the beginning of the filename ".htaccess" is important.
In your .htaccess file, put one line:
ErrorDocument 404 http://www.whatever.com/my404file.html
The 3rd item on that line should be a complete URL which points to the HTML file which you want users to see when they try to access a file which doesn't exist. There are a couple of things to keep in mind about .htaccess files:
1. They are "recursive". The .htaccess file in your public_html directory will affect all subdirectories. If you want to have different 404 messages for different parts of your site, you can put more .htaccess files in other subdirectories. The .htaccess files at lower levels in the directory tree will override the settings set at higher levels. 2. If you already have .htaccess files to do access controls, just add the ErrorDocument line near the top of the file. Make sure it is OUTSIDE and <LIMIT> statements in the file. 3. The .htaccess file needs to be world-readable in order to work. If you're working in Unix, "chmod 644 .htaccess" will set the appropriate permissions. If you're uploading the file with FTP, it will likely be set to the correct permissions. 4. If you are using Front Page, this may not work. Front Page uses .htaccess files as part of its setup and your change (adding an ErrorDocument line) may get deleted by Front Page sometime down the road.