What A .htaccess File Is And How To Make One

A .htaccess file is a simple ASCII file similar to thatthose that would prevent the user from forgetting
created through text editor such as Notepad or Simplewhat the page is being used for.
Text. Most people are confused with the namingPassword protection is effectively dealt with by
convention for the file. The term .htaccess is not a file.htaccess. By creating a file called .htpasswd,
.htaccess or somepage.htaccess because it is the fileusername and the encrypted password of the people
extension simply named as such. Its widely known useto be allowed access are placed in the .htpasswd file.
is related to implementing custom error page orThe .htpasswd file should likewise be not uploaded to a
password protected directories.directory that is web accessible for maximum security.
Creating the FileWhole directories of a site can be redirected using the
The creation of the file is done by opening up a text.htaccess file without the need to specify each file.
editor and saving an empty page as .htaccess. If it isThus any request made for an old site will be
not allowed to save an empty page, simply type in oneredirected to the new site, with the extra information in
character. An editor probably appends its default filethe URL added on. This is a very powerful feature
extension to the name. Notepad for one would call thewhen used correctly.
file .htaccess.txt but the .txt or other file extensionAside from custom error pages, password protecting
need to be removed to enable the user to startfolders and automatic redirection of users, .htaccess is
"htaccessing". This can be done by clicking the file andalso capable of changing file extension, banning users
renaming it by removing anything that doesn't saywith extra certain IP address allowing only users with
.htaccess. It can also be renamed via telnet or the ftpcertain IP addresses, stopping directory listing and using
program.a different file as the index file. Accessing a site that
These files must not be uploaded as binary but ratherhas been protected by .htaccess will require a
as ASCII mode. Users can CHMOP the .htaccess filebrowser to pop-up a standard username/password
to 644 to make the file usable by the server whiledisplay box. However, there are certain scripts
preventing it from being read by a browser since thisavailable which will allow the user to embed a
can seriously compromise security. When there areusername/password box in a website to do the
passwords protected directories and a browser canauthentication. The wide variety of uses of .htaccess
read the .htaccess file, the location of thefacilitates time saving options and increased security in
authentication file can be acquired to reverse engineera website.
the list and thereby completely access any portion thatMany hosts support .htaccess but do not publicize it
had previously been protected. This can be preventedwhile many others have the capability for it but do not
by either placing all authentication files above rootallow their users to have an .htaccess file. Generally, a
directory thereby rendering the www inaccessible orserver that runs UNIX or any version of the Apache
through an .htaccess series of commands thatweb server will support .htaccess although the host
prevents itself from being accessed by a browser.may not allow its use.
Most commands in .htaccess are meant to be placedWhen to Use .htaccess Files
on one line only thus if a text editor uses word wrap, itThe .htaccess files should not be used when there is
should be disabled as it is possible that it might throw inno access to the main server configuration file.
a few characters that might contradict Apache.Contrary to common belief, user authentication is not
.htaccess is not for NT servers and is considered analways done in .htaccess files. The preferred way is to
Apache thing. Apache is generally very tolerant ofput user authentication configuration in the main server
malformed content in an .htaccess file.configuration.
The directory in which .htaccess file is placed isIt should be used in situations where the content
"affected" as well as all sub-directories. It a userprovider needs to make configuration changes to the
wishes not to have certain .htaccess commandsserver on a per-directory basis but does not have root
affect a specific directory, this is done by placing aaccess on the server system. Individual users can be
new .htaccess file within the directory that should notpermitted to make these changes in .htaccess files for
be affected with certain changes and removing thethemselves if the server administrator is unwilling to
specific command/s. from the new .htaccess file whichmake frequent configuration. As a general rule, the use
should not affect the directory. The nearest .htaccessof .htaccess should be avoided when possible since
file to the current directory is the one considered asconfiguration can be effectively made in a Directory
the .htaccess file. A global .htaccess located in the root,Section in the main server configuration file.
if considered the nearest, affects every singleTwo main factors warrant avoiding the use of
directory in the entire site..htaccess files - performance and security. Permitting
Placement of .htaccess should not be done.htaccess files causes a performance hit whether or
indiscriminately as this may result to redundancy andnot it is actually used, since Apache will look in every
may cause an infinite loop of redirects or errors. Theredirectory for such file. The .htaccess file is also looked
are sites that do not allow the use of .htaccess filesinto every time a document is requested. The Apache
because a server overloaded with domains can besearch will include .htaccess files in all higher-level
slowed down when all are using .htaccess files. It isdirectories to have a full complement of directories of
possible that .htaccess can compromise a serverapplication. As such, each file accessed out of the
configuration specifically set-up by the administrator. Itdirectory results to 4 additional file system accesses
is therefore necessary to make sure that the use ofeven if none was originally present.
.htaccess is allowed before its actual use.The use of .htaccess permits users to modify server
Error documents are only a part of the general use ofconfiguration which may produce uncontrolled changes.
.htaccess. Specifying one's own customized errorThis privilege should be carefully considered before it is
documents will require a command within the .htaccessgiven to users. The use of the .htaccess files can be
file. The pages can be named anything and can becompletely disabled by setting the Allow Overide
placed anywhere within the site as long as they aredirective to none.
web-accessible through a URL. The best names are