How to create an .htaccess file:
Note: .htaccess is the file extension. It is not file.htaccess or somepage.htaccess, it is just named .htaccess
General notes on .htaccess
Use .htaccess to password protect a directory
You can use .htaccess to password a directory on your server. There are numerous approaches to creating an authentication system. Htaccess can be used for passwords. Place the username and password in the htpasswd file.
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Directory To Be Protected"
Require valid-user
The full/path/to/.htpasswd should be the full path to the .htpasswd file. On Windows for instance, it could look like this: C:\wwwrootlevel\username\.htpasswd.
The above .htaccess file will password protect all files in the folder that it is placed in, including all sub-folders as well.
Use .htaccess to protect a single file
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"
<Files "mywebfile.html">
Require valid-user
</Files>
This script will password-protect just the mywebfile.html file in the folder where you put the .htaccess file.
Change your default directory page
You can specify a certain file to be your index file (directory index). By default, index.html or index.htm is often the default index for directories. Let's say you wanted to use a different file as your directory index, you could by using .htaccess to specify the file.
DirectoryIndex filename.html
Redirects using .htaccess
You can create redirects using .htaccess as well. For example, 301 permanent redirects are very important for SEO purposes since they let Google and other search engines know if a file has been moved and where to find this file.
Redirect /olddirectory/oldfile.html https://yoursite.com/newdirectory/newfile.html