Knowledgebase: Custom
404 & .htaccess
What
is a custom 404 page?
A custom 404 page is simple a customized error page for your visitors.
What does this do for you? It can help you retain visitors who may leave
if they get the standard "File not found" page. The standard
error page isn't very appealing and if the person came from another site's
link- that potential visitor may just leave. However, you can make your
404 page much more informative, and provide your visitors with a way to
navigate through your site. Instead of a "File Not Found" and
not much else, you can send them an error page with a professional appearance.
How
do I create my own custom 404 page?
To create a custom 404 page you must first create a .htaccess file in
your www folder. Because of the hidden nature of the .htaccess file it
will not appear in the file manager or through ftp, however as long as
you follow these instructions it will still work correctly.
Then place this in the .htaccess file - this is the only line of code
to be placed in it You would do somthing similiar for a 403 error message.
ErrorDocument 404 http://yourdomain.com/file.html
What
is .htaccess?
The .htaccess file can be placed in one or more of your /home/username/domainname-www
subdirectories. Among other things, this file can be used to restrict
access to other files and web pages. When a request for a web page is
made, the web server first checks for an .htaccess file. The server begins
this check by looking for .htaccess in the root of the current web directory,
and on down the directory tree until it reaches the the directory where
the requested file resides. Since the placement of the .htaccess file
determines when it is executed, this fact can be used to restrict access
only in certain subdirectories.
How
do I create a .htaccess file?
Important Note: Do not edit the .htaccess file if you are using MS Frontpage!
Frontpage uses the .htaccess file, and editing it may cause errors in
your configuration.
The .htaccess file can be placed in one or more of your /home/$user/$domain-www
subdirectories. Among other things, this file can be used to restrict
access to other files and web pages.
When a request for a web page is made, the web server first checks for
an .htaccess file. The server begins this check by looking for .htaccess
in the root of the current web directory, and on down the directory tree
until it reaches the directory where the requested file resides. Since
the placement of the .htaccess file determines when it is executed, this
fact can be used to restrict access only in certain subdirectories.
Functions:
- Restrict access to directories using passwords.
- Redirect hits onto another webpage.
- Control and set the messages generated for various error conditions.
- Edit Mime-types.
- Activate and deactivate various server features.
To create an .htaccess file, make a text file as described below, name
it .htaccess and upload it.Except for the first feature, described below,
the following features will only work for a .htaccess file placed in /home/$user/$domain-www.
Add all features you want to the same file.
----------------------------------------
Restricting Access: Password Protection
The directory you want protected must have a .htaccess file in it that
looks like the following (do not put the comments in the actual .htaccess
file [comments begin with #]):
AuthUserFile /home/$user/.passwd
AuthGroupFile /home/$user/.group
AuthName "Protected Space"
AuthType Basic
<Limit GET>
require group $users #users, is the group of users that you give access
to
#require user $user #if there is only one user in the group, you can substitute
this line; remove the #.
</Limit>
(Other possible groups are administrators, etc)
Groups and users are stored in the .group file, and passwords are stored
in .passwd. The .htaccess file looks for these files in the /home/$user
directory. Do not attempt to edit these manually! Alabanza has a special
script you can use to manage your .group and .passwd files (the "webmister"
script). Ask support to install it for you.
-----------------------------------------
Redirects
Redirecting allows you to send the user to, for example, new.html when
they attempt to access old.html. To see this example in practice, simply
add the following line to the .htaccess file:
Redirect /$directory/old.html http://$domain.com/$directory/new.html
------------------------------------------
Error Documents
There are two main styles of error messages you may encounter. The first
is the standard form, which looks something like:
File Not found
The requested URL http://$domain.com/file.html was not found on this server.
The second type comes in a variety of forms, and is customized by the
webmaster. For example:
Sorry
We're sorry, but the requested URL does not exist. Please e-mail support@$domain.com
if you need further assistance.
Such messages are called error documents, and are web pages designed to
give a polite explanation for error conditions. These error conditions
generate numbers which are used to refer to the appropriate error condition.
Some of the most common messages are as follows:
Error in Client
400 Bad syntax
401 Unauthorized
402 Not Used (Payment Granted)
403 Forbidden
404 Not Found
Error in Server
500 Internal Error
501 Not Implemented
502 Overloaded
503 Gateway Timeout
How to Customize Error Messages for Your Site:
First, create the HTML page you want to use as your error message.
Second, upload it to your web directory [/home/$user/$domain-www].
Third, go into your .htaccess file (or create one) and add lines which
specify the substitution.
Here are three examples of specifying error documents which will be called
for a given error condition (note you can use relative or absolute addressing):
ErrorDocument 401 http://$domain.com/nopasswd.html
ErrorDocument 403 /forbidden.html
ErrorDocument 404 http://www.$domain.com/nofile.html
-----------------------------------------
Mime Types
You can add mime types to your .htaccess file with a line like:
AddType text/html .txt
I
created a .htaccess file but cannot see it. Why?
We do not allow hidden files on our servers to be seen any other way except
via SSH. Therefore to view you hidden .htaccess file you will need to
ftp into your account using SSH. Hidden files start with a '.'
Does
.htaccess work with Frontpage?
If you're running FrontPage, you cannot custom-edit the .htaccess file.
You'll either create a security hole or break FrontPage. There are no
other options. This @includes ANY .htaccess file in your domain, including
one in the cgi-bin.Having said this, please note that a .htaccess file
may be used in any directory within the webspace that is not owned by
the user; for example, a directory owned by root.
Can
I block a certain IP address from accessing my site?
Create a .htaccess file, and place it inside of your /home/username/domain-www
directory. The .htaccess file must contain the following:
order deny,allow
deny from all
order allow,deny
allow from all
deny from 000.000.000.000
You may block multiple IP's by seperating the addresses with a space.
Can
I protect my images so people can't steal them?
Yes, you can create an .htaccess file to block people from stealing or
linking to your images. For more information on how the .htaccess file
must be configured please contact Burningbulb. net by opening a technical
support ticket.
© 2003 Burningbulb.net |