What is the HTACCESS file format?
.htaccess is an Apache web server configuration file. Unlike most files, .htaccess does not include a filename before the dot - the leading dot is part of the name itself, making it a hidden file by default on Linux and macOS. .htaccess files should not be manually edited by unauthorized or unqualified users. The file stores all configuration in plain text.
.htaccess files contain per-directory configuration settings that define server functions such as:
- the index (default) page of a directory,
- access restrictions for specific IP addresses,
- custom error pages (e.g., 404 Page Not Found),
- URL redirects and rewrites (
RewriteRule/RewriteCond), - password-protecting directories (
AuthType,AuthUserFile), - additional server security settings and custom HTTP response headers.
For .htaccess to take effect, AllowOverride must be set to something other than None in the parent httpd.conf - on hardened servers, .htaccess processing is often disabled entirely.
Because Apache reads .htaccess on every HTTP request to its directory, it carries a measurable performance cost. Apache's own documentation recommends placing equivalent directives in server or VirtualHost configuration blocks instead, as those are loaded only once at startup.
.htaccess is specific to Apache; Nginx does not support it and requires equivalent rules in nginx.conf. The companion file .htpasswd stores hashed credentials for HTTP Basic Authentication.
Security & safety
RISK: HIGH.htaccess itself is a harmless text file to open in an editor. However, it represents a CRITICAL attack surface on web servers: 1. Upload attack: if a web app lets users upload files into a web-accessible directory and Apache's AllowOverride permits .htaccess, an attacker who uploads a crafted .htaccess can re-enable PHP execution in an upload directory and run webshells. Mitigation: store uploads outside the document root; set AllowOverride None for upload directories; block .htaccess creation in upload directories. 2. Information disclosure: a misconfigured server that serves .htaccess as a text file (instead of blocking access to dotfiles) exposes server configuration, directory structure, and potentially credentials references. Apache's default configuration blocks access to .htaccess files (FilesMatch ^\.ht).
Format details
in a nutshellPrograms that open HTACCESS files
Technical details
deep spec| Origin | Inherited from NCSA HTTPd (1994); Apache HTTP Server has supported it since version 1.0 (1995) |
| Filename | Dotfile - the complete filename is `.htaccess`; hidden by default on Unix and macOS |
| File type | Plain-text per-directory Apache configuration |
| Encoding | UTF-8 or ASCII (must match server locale) |
| Typical file size | 100 bytes - 50 KB (most files under 5 KB) |
| Processing frequency | Read by Apache on every HTTP request to the containing directory and all subdirectories |
| Prerequisite | `AllowOverride` must not be `None` in the parent `httpd.conf`; otherwise `.htaccess` is silently ignored |
| Common directives | `RewriteRule`, `RewriteCond`, `ErrorDocument`, `AuthType`, `AuthUserFile`, `Header`, `Options`, `Redirect` |
| Access control syntax | Apache 2.4 replaced `Allow`/`Deny` with `Require`; older syntax requires `mod_access_compat` |
| Nginx compatibility | Not supported by Nginx; rules must be manually translated to `nginx.conf` directives |
| Performance note | Causes per-request disk reads; Apache recommends preferring `httpd.conf` or VirtualHost blocks for configuration |
| Security risk | An attacker-uploaded `.htaccess` in a writable web directory can enable server-side script execution |
| Released | 1994 (NCSA HTTPd, predecessor to Apache; Apache inherited it from 1995) |
| Latest version | Apache HTTP Server 2.4.x directive syntax (current) |
| Open standard | Yes · royalty-free |
| Specification | httpd.apache.org |
HTACCESS conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about HTACCESS files.