.htaccess
.htaccess is a configuration file used by the Apache server (and the compatible LiteSpeed) that lets you override server settings within the directory it sits in and all of its subdirectories. Its biggest advantage is that changes take effect immediately, with no service restart and no access to the main configuration — so on shared hosting every customer can control their own site's behavior even though the provider manages the server.
How .htaccess works
On every request, Apache checks whether the path to the requested file contains any .htaccess files and applies the directives inside them. Rules are written in a simple text syntax, and the most commonly used component is the mod_rewrite module, which rewrites and redirects addresses. This flexibility has a cost: checking these files on every request adds more load than a central configuration, so under heavy traffic .htaccess is sometimes disabled in favor of rules in the main config.
Practical application
Typical tasks handled by .htaccess include:
- Redirects — such as a 301 redirect from an old address to a new one, or forcing the www or non-www version.
- Pretty URLs — hiding parameters and creating readable URLs that WordPress, PrestaShop and Joomla depend on.
- Directory protection — password protection (paired with an .htpasswd file) or blocking access by IP address.
- Headers and performance — setting security headers, gzip compression or browser caching.
A single syntax error can make the whole site return a 500 error, so it's wise to back up the file before editing. On a typical hosting account with a DirectAdmin panel, .htaccess is the main configuration tool available to the user.
Powiązane pojęcia
Najczęstsze pytania
Why does the filename start with a dot?
On Unix-like systems, files beginning with a dot are hidden and don't appear in a default directory listing. The name stands for 'hypertext access', and the convention protects the config file from being accidentally displayed or deleted by a user.
Does .htaccess work on Nginx?
No. The .htaccess file is a feature of Apache and compatible servers such as LiteSpeed. Nginx does not read these files — its redirect and access rules are defined centrally in the server configuration, which is more efficient but requires administrative access.
