;
Authorization and
authentication: A .htaccess file commonly restricts access to a directory. It is often paired with a
.htpasswd file that stores usernames and
password hashes. ;
URL rewriting: Servers use .htaccess with
mod_rewrite to rewrite long or complex URLs to shorter, more readable forms. ; Access control: The Allow and Deny directives (or Require in Apache 2.4) restrict access by IP address, domain, or other criteria, and can block unwanted bots or referrers. ;
Server-side includes: The Options +Includes directive enables server-side include processing for a directory. ; Directory listing: The Options directive controls whether the server generates an automatic index when no default document is present. ;
Custom error responses: The ErrorDocument directive maps HTTP error codes—such as
404 Not Found or
301 Moved Permanently—to custom pages. ;
MIME types: The AddType directive instructs Apache how to serve files with non-standard or missing extensions. ; Cache control: .htaccess files can set Cache-Control and Expires headers via mod_headers or mod_expires, reducing bandwidth use and server load. ;
HTTPS and
HSTS: Enforcing HTTPS on Apache typically requires RewriteRule directives and Header directives in .htaccess. Syntax errors in these rules can cause failed redirects or broken HSTS deployment. ==Advantages==