2. Apache .htaccess Syntax, Tutorial
Syntax Apache .htaccess
.htaccess file syntax rules :
- one directive per line
- maximum length of a line = 8192 characters
- one commented directive per line
- the hash # character allows you to comment a directive → ignored directive
- backslash "\" as directive's last character → the directive continues onto the next line (line breaks)
- directives may be indent for clarity; blank lines and spaces before directives are ignored
- directives are case-insensitive
- arguments to directives are often case sensitive
- shell environment variables can be used, syntax is: ${VARIABLE}
Video demonstration Syntax Apache .htaccess
Syntax Apache .htaccess Tutorial
min | video details |
---|---|
00:01 | Syntax .htaccess Tutorial /Apache 2.2 |
00:10 | one valid directive per line |
00:16 | one valid directive per 2 lines: possible if using the backslash "\" as directive's last character; the directive continues onto the next line |
00:22 | no other character or white space allowed between backslash and the end of the line |
00:29 | Test: currently index.php delivered |
00:34 | if index.php is not available, the server will deliver index.html |
00:39 | making the index.php 'unavailable' by altering its name |
00:44 | Note: index.html displays the "It works!" text |
00:49 | Test result: ok index.html delivered because index.php was not available → the directive split onto 2 lines works |
01:02 | one commented directive per line (this one does not apply, it is commented, see the hash character # at the beginning of the line) |
01:08 | blank lines between directives allowed (are ignored) |
01:15 | spaces before directives allowed (are ignored); directives may be indent for clarity |
01:20 | directives are case-insensitive |
01:23 | arguments to directives are often case sensitive |
For more information about the apache.org
file, please see the spec: