An .htaccess file is a hidden file like any other beginning with a dot. They are else called dotfiles. An .htaccess file is an ASCII file. In fact, .htaccess is not the name of the file, it is a file extension. It is not somename.htaccess file, it is just .htaccess.
For the safety, it is better to upload .htaccess files to the subdirectory. At least, test them there. Mistakes in the code of htaccess file located in the root directory can cause very serious problems with access to your hosting account through cPanel or FTP.
To see if my hosting account allows to use me hidden files, I went to cPanel, the “Files” section and clicked on the icon of the File Manager. The dialogue “File Manager Directory Selection” appeared before entering the File Manager. There I checked the box “Show hidden files (dotfiles)”.
I saw dotfiles in my root directory, so I could also create and use such files.
I created a plain text editor file. The file can be empty. (At this step you can already put the code line in the text file but note that the word-wrap should be disabled as most code lines in .htaccess should be written in one line.)
I named it as I liked.
I uploaded it to my server to the proper directory through the File Manager in cPanel.
I renamed the file into .htaccess in the File Manger.
I edited it with the text editor, pasted the necessary code.
I set permissions to 644 for this file.
Note that if there is already an .htaccess file in your directory/subdirectory, and you are going to upload another .htaccess file, it will be replaced by the new one. So, search carefully for dotfiles before creating the one.