The .htaccess file is a file used by the free software Apache, the software that a server uses to run.
WordPress creates it automatically during installation to include the site’s permalink settings. The file is modified when you change the URL format in Settings > Permalinks. But that’s not all it’s used for.
A site can have several .htaccess files. The main .htaccess file is located at the root of the site, where the WordPress files are located.
An .htaccess file placed in a directory will act on the directory in which it is located as well as on all its sub-directories. The content of the main .htaccess file will therefore have an influence on the whole site.
Other .htaccess files can be created in subdirectories. For example, one can place one in the wp-content/uploads directory for example. In this case, the secondary .htaccess files will only have an influence on the uploads directory and all its subdirectories.
It is quite simple to customize the code of an .htaccess file, but you still have to take some precautions and save the initial content of the file before modifying it. In case of a problem, you can easily restore the original content.
Check out The ultimate guide to the .htaccess file in WordPress to learn more about the different possibilities of customizing this file.