A per-directory configuration file holds directives for its directory and everything below it, as if written in a <Directory> block. Its name is set by AccessFileName, .htaccess by default; the format comes from NCSA HTTPd, and LiteSpeed 17,276 reads it too. It is re-read on every request, so edits apply without a reload, but only if AllowOverride permits (AllowOverride). This one needs FileInfo Indexes and mod_headers:
# /var/www/example/.htaccess - read on every request, no reload needed
DirectoryIndex home.html index.html
ErrorDocument 404 /errors/404.html
AddType text/markdown .md
AddDefaultCharset UTF-8
Header set X-Config-Source "htaccess"The lines pick the directory's page, replace the built-in 404 page, map an extension /etc/mime.types lacks, label text/html and text/plain as UTF-8, and prove the file was read. The last command edits the file with Apache 129 running:
curl -si localhost:8104/
curl -s -o /dev/null -w '%{http_code} %{content_type}\n' localhost:8104/missing
curl -s -o /dev/null -w '%{http_code} %{content_type}\n' localhost:8104/notes.md
curl -s -o /dev/null -w '%{http_code}\n' localhost:8104/.htaccess
sed -i 's/home.html/index.html/' .htaccess && curl -s localhost:8104/HTTP/1.1 200 OK ... X-Config-Source: htaccess Content-Type: text/html; charset=UTF-8 <h1>Home page</h1> 404 text/html; charset=UTF-8 200 text/markdown 403 <h1>Index</h1>
The 403 comes from Ubuntu 225 's <FilesMatch "^\.ht"> block in apache2.conf, which hides your rules and any .htpasswd file. Keep it: write access to a directory is now write access to its configuration.