X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=docs%2Fmanual%2Fhowto%2Fhtaccess.html.en;h=fc58f1127499fd7947fac8e8dca4fb4c226e6d25;hb=6f41ecf8ea11fde431bb1be94a10cbb68a8cdf56;hp=61adfa4fbb0b1b3d05ca1559e36424fb783acb9b;hpb=dd8bdc09d245f70ce022977a0b1e5d93758bc186;p=apache diff --git a/docs/manual/howto/htaccess.html.en b/docs/manual/howto/htaccess.html.en index 61adfa4fbb..fc58f11274 100644 --- a/docs/manual/howto/htaccess.html.en +++ b/docs/manual/howto/htaccess.html.en @@ -1,27 +1,30 @@ - -Apache HTTP Server Tutorial: .htaccess files - Apache HTTP Server +Apache HTTP Server Tutorial: .htaccess files - Apache HTTP Server Version 2.5 - +
<-
Apache > HTTP Server > Documentation > Version 2.5 > How-To / Tutorials

Apache HTTP Server Tutorial: .htaccess files

+

See also

top

.htaccess files

- +
You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. @@ -65,7 +69,7 @@ changes on a per-directory basis.

if you would rather call the file .config then you can put the following in your server configuration file:

-
AccessFileName .config
+
AccessFileName ".config"
@@ -187,21 +191,19 @@ changes on a per-directory basis.

Note that it is completely equivalent to put a .htaccess file in a directory /www/htdocs/example containing a directive, and to put that same directive in a Directory section - <Directory /www/htdocs/example> in your main server + <Directory "/www/htdocs/example"> in your main server configuration:

.htaccess file in /www/htdocs/example:

Contents of .htaccess file in - /www/htdocs/example

AddType text/example .exm
+ /www/htdocs/example
AddType text/example ".exm"

Section from your httpd.conf - file

-<Directory /www/htdocs/example>
-    AddType text/example .exm
-</Directory>
-    
+ file
<Directory "/www/htdocs/example">
+    AddType text/example ".exm"
+</Directory>

However, putting this configuration in your server configuration @@ -259,22 +261,20 @@ changes on a per-directory basis.

As discussed in the documentation on Configuration Sections, .htaccess files can override the <Directory> sections for - the corresponding directory, but will be overriden by other types + the corresponding directory, but will be overridden by other types of configuration sections from the main configuration files. This fact can be used to enforce certain configurations, even in the presence of a liberal AllowOverride setting. For example, to prevent script execution while allowing anything else to be set in .htaccess you can use:

-
-<Directory /www/htdocs>
+    
<Directory "/www/htdocs">
     AllowOverride All
 </Directory>
 
-<Location />
-    Options +IncludesNoExec -ExecCGI
-</Location> -
+<Location "/"> + Options +IncludesNoExec -ExecCGI +</Location>
This example assumes that your DocumentRoot is /www/htdocs.
@@ -301,13 +301,11 @@ changes on a per-directory basis.

.htaccess file contents:

-
-AuthType Basic
+    
AuthType Basic
 AuthName "Password Required"
-AuthUserFile /www/passwords/password.file
-AuthGroupFile /www/passwords/group.file
-Require Group admins
-    
+AuthUserFile "/www/passwords/password.file" +AuthGroupFile "/www/passwords/group.file" +Require group admins

Note that AllowOverride AuthConfig must be in effect @@ -324,11 +322,9 @@ Require Group admins the following configuration directives, placed in a .htaccess file in the desired directory:

-
-Options +Includes
-AddType text/html shtml
-AddHandler server-parsed shtml
-    
+
Options +Includes
+AddType text/html "shtml"
+AddHandler server-parsed shtml

Note that AllowOverride Options and AllowOverride @@ -337,6 +333,34 @@ AddHandler server-parsed shtml

Please see the SSI tutorial for a more complete discussion of server-side includes.

+
top
+
+

Rewrite Rules in .htaccess files

+

When using RewriteRule in +.htaccess files, be aware that the per-directory context +changes things a bit. In particular, rules are taken to be relative to +the current directory, rather than being the original requested URI. +Consider the following examples:

+ +
# In httpd.conf
+RewriteRule "^/images/(.+)\.jpg" "/images/$1.png"
+
+# In .htaccess in root dir
+RewriteRule "^images/(.+)\.jpg" "images/$1.png"
+
+# In .htaccess in images/
+RewriteRule "^(.+)\.jpg" "$1.png"
+ + +

In a .htaccess in your document directory, the leading +slash is removed from the value supplied to RewriteRule, and in the +images subdirectory, /images/ is removed from +it. Thus, your regular expression needs to omit that portion as +well.

+ +

Consult the mod_rewrite documentation for +further details on using mod_rewrite.

+
top

CGI example

@@ -345,20 +369,16 @@ AddHandler server-parsed shtml the execution of CGI programs in a particular directory. This may be implemented with the following configuration:

-
-Options +ExecCGI
-AddHandler cgi-script cgi pl
-    
+
Options +ExecCGI
+AddHandler cgi-script "cgi" "pl"

Alternately, if you wish to have all files in the given directory be considered to be CGI programs, this may be done with the following configuration:

-
-Options +ExecCGI
-SetHandler cgi-script
-    
+
Options +ExecCGI
+SetHandler cgi-script

Note that AllowOverride Options and AllowOverride @@ -413,6 +433,7 @@ SetHandler cgi-script

Available Languages:  en  | + es  |  fr  |  ja  |  ko  | @@ -435,7 +456,7 @@ var comments_identifier = 'http://httpd.apache.org/docs/trunk/howto/htaccess.htm } })(window, document); //-->