What is .htaccess
.htaccess stands for HyperText Access. It is a type of distributed configuration file used by Apache web servers to manage access to directories and the resources within them in certain situations. .htaccess files are text documents that take certain parameters that are understood and implemented by Apache web servers.
Why are .htaccess files important on a WordPress website?
Htaccess files are important as they allow us to easily configure directory and file permissions, and access rights on a directory basis, without having to access the main Apache configuration file. Because they’re very versatile .htaccess files can also be used to protect directories, prevent hotlinking, restrict access, and configure custom error pages among other things.
Since .htaccess files work on a directory basis, you can put as many as one in each folder, giving you very granular access control. Do be aware, however, that this would make it very difficult to manage and is discouraged.
Having too many .htaccess files can also contribute to website slowdowns, since Apache would need to load each one every time someone visits your website. In fact, Apache recommends using .htaccess files only if you do not have access to the main configuration file.
How .htaccess files work
.htaccess files are text files used to implement directives. It is written in the same syntax as the main configuration file, with one directive allowed per line and ‘#’ preceding comments.
Usage of the .htaccess file must be specified in the main configuration file through the AllowOverride directive. Under this directive, directive categories that can be overridden in the .htaccess file must be specified. The .htaccess extension can also be changed using the AccessFileName directive.
Directives listed in a .htacess file are applied to the directory in which it resides and all of its child directories. .htaccess files in child directories override any directives listed in .htaccess files in parent directories.
How to manage .htaccess files
.htaccess files should not be used unless you do not have access to the main configuration file. This is because Apache has to load all .htaccess files whenever a visitor visits the website which can leave to performance degradation in high-traffic websites or websites that do not have ample resources.
.htaaccess files can be accessed the same way you access WordPress files and folders, and edited using Notepad or any similar program. If you’re editing directly on the server, you can use vi or vim and remember to remove backup files from WordPress.
Even with the right .htaccess directives in place, you should monitor WordPress file changes and WordPress user activity across your website’s resources. The more comprehensive the WordPress security policy, the safer your website will ultimately be.« Back to Glossary Index