From: Daniel Gruno .htaccess files provide a way to make configuration
changes on a per-directory basis.
.htaccess files completely if you have access to
- httpd main server config file. Using .htaccess files slows down your Apache server.
- Any directive that you can include in a .htaccess file is
- better set in a .htaccess files slows down your Apache http server.
+ Any directive that you can include in a .htaccess file is better set in a In general, .htaccess files use the same syntax as
the main configuration
- files. What you can put in these files is determined by the
+ files. What you can put in these files is determined by the
.htaccess file. If a
@@ -129,13 +126,16 @@ changes on a per-directory basis.
In general, you should never use .htaccess files unless
+
In general, you should only use .htaccess files when
you don't have access to the main server configuration file. There is,
- for example, a prevailing misconception that user authentication should
- always be done in .htaccess files. This is simply not the
+ for example, a common misconception that user authentication should
+ always be done in .htaccess files, and, in more recent years,
+ another miscomception that .htaccess files. This is simply not the
case. You can put user authentication configurations in the main server
configuration, and this is, in fact, the preferred way to do
- things.
mod_rewrite directives work better,
+ in many respects, in the main server configuration.
.htaccess files should be used in a case where the
content providers need to make configuration changes to the server on a
@@ -159,18 +159,18 @@ changes on a per-directory basis.
The first of these is performance. When .htaccess files, Apache will
+ is set to allow the use of .htaccess files, httpd will
look in every directory for .htaccess files. Thus,
permitting .htaccess files causes a performance hit,
whether or not you actually even use them! Also, the
.htaccess file is loaded every time a document is
requested.
Further note that Apache must look for .htaccess files
+
Further note that httpd must look for .htaccess files
in all higher-level directories, in order to have a full complement of
directives that it must apply. (See section on how
directives are applied.) Thus, if a file is requested out of a
- directory /www/htdocs/example, Apache must look for the
+ directory /www/htdocs/example, httpd must look for the
following files:
.htaccess files were enabled for /, which
is not usually the case.)
+ In the case of .htaccess context these regular expressions must be
+ re-compiled with every request to the directory, whereas in main
+ server configuration context they are compiled once and cached.
+ Additionally, the rules themselves are more complicated, as one must
+ work around the restrictions that come with per-directory context
+ and mod_rewrite. Consult the Rewrite Guide for more
+ detail on this subject.
The second consideration is one of security. You are permitting users to modify server configuration, which may result in changes over which you have no control. Carefully consider whether you want to give @@ -207,7 +218,7 @@ changes on a per-directory basis.
/www/htdocs/examplehttpd.conf
@@ -216,12 +227,12 @@ changes on a per-directory basis.
However, putting this configuration in your server configuration file will result in less of a performance hit, as the configuration is - loaded once when Apache starts, rather than every time a file is + loaded once when httpd starts, rather than every time a file is requested.
The use of .htaccess files can be disabled completely
@@ -281,10 +292,10 @@ changes on a per-directory basis.
.htaccess files can override the .htaccess you can use:
@@ -297,7 +308,7 @@ Allowoverride AllNote that AllowOverride AuthConfig must be in effect
@@ -350,7 +361,7 @@ Options +IncludesNoExec -ExecCGI
AddType text/html shtml
- AddHandler server-parsed shtml
+AddHandler server-parsed shtml
Note that Alternately, if you wish to have all files in the given directory be
@@ -378,7 +389,7 @@ Options +IncludesNoExec -ExecCGI Note that If, on the other hand, you are getting server errors when trying to
- access documents, check your Apache error log. It will likely tell you
+ access documents, check your httpd error log. It will likely tell you
that the directive used in your AllowOverride Options and AllowOverride
@@ -369,7 +380,7 @@ Options +IncludesNoExec -ExecCGI
- AddHandler cgi-script cgi pl
+AddHandler cgi-script cgi pl
- SetHandler cgi-script
+SetHandler cgi-script
AllowOverride Options and AllowOverride
@@ -401,15 +412,35 @@ Options +IncludesNoExec -ExecCGI
set such that your configuration directives are being honored. Make
sure that you don't have a AllowOverride None in effect
for the file scope in question. A good test for this is to put garbage
- in your .htaccess file and reload. If a server error is
+ in your .htaccess file and reload the page. If a server error is
not generated, then you almost certainly have AllowOverride
None in effect..htaccess file is not
- permitted. Alternately, it may tell you that you had a syntax error,
- which you will then need to fix.
This will indicate either that you've used a directive that is
+ never permitted in .htaccess files, or that you simply
+ don't have
Alternately, it may tell you that you had a syntax error in your + usage of the directive itself.
+ +In this case, the error message should be specific to the + particular syntax error that you have committed.
On systems with multiple users, each user can be permitted to have a
- web site in their home directory using the http://example.com/~username/ will get content
out of the home directory of the user "username", out of
the subdirectory specified by the
Note that, by default, access to these directories is not
+ enabled. You can enable access when using
in the default config file, and adapting the httpd-userdir.conf
+ file as necessary, or by including the appropriate directives in a
+ Directory block within the main config file.
For the URL http://example.com/~rbowen/file.html,
- Apache will search for ~rbowen. If it isn't found,
+
For the URL http://example.com/~rbowen/file.html,
+ Apache will search for ~rbowen. If it isn't found,
Apache will search for rbowen in /var/html. If
- found, the above URL will then be translated to the file path
+ found, the above URL will then be translated to the file path
/var/html/rbowen/file.html
The
The above example will redirect a request for
http://example.com/~bob/abc.html to
http://example.org/users/bob/abc.html.
Using the syntax shown in the UserDir documentation, you can restrict
@@ -160,7 +169,7 @@
<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
- </Directory>
+</Directory>
Then, presuming that UserDir is set to