Htaccess can be useful for accomplishing many different things pertaining to websites. Here is a list of some of the common things htaccess can do...
Force website visitors to use the https version of a website for a more secure connection. Due to the facts that https gives a speed boost and causes websites to load faster than their http equivalent, most prominent browsers indicate whether or not the connection to a website is secure if it is the https version being used, and not secure if the http version is being used, it would be in the best interest of a website owner to make sure people visiting their website always use the secure https version of the website. This is almost mandatory these days for all websites and is especially mandatory for websites that sell products and require the use of a credit card from people who want to buy those products.
Force website visitors to use the www version of a website rather than the non-www version and vice versa.
Remove the index file from the URL for the home page of the site. E.g. example.com/index.html would be changed to example.com.
Allow the name of a file to be in the URL without the extension of the file attached to it. E.g. example.com/file will work even without it having to be example.com/file.html.
Remove the extension of a file in the URL. E.g. example.com/file.php would become example.com/file.
Removing the extension of a file in the URL can make the URL easier to remember and more presentable to search engines as well as real people the URL/link may be shared with.
Block unwanted bots that can potentially use up server resources among other undesirable things that aren't beneficial to the website. Aside from bots, specific IP addresses can be blocked via htaccess.
Redirect pages that aren't found on a website to a custom 404 page. Creating a custom 404 page can be good because it can make a website visitor feel like they're still on the website even though the page they attempted to go to was not found. The aesthetics of the website would still be present and they can still see the navigation menu so they would be more likely to stay on the site and go to other pages. Without a custom 404 page, the server will just show the website visitor a plain white page with a 404 error message.
Redirect an old domain to a new domain or an old page to a new page. E.g. If someone goes to old.example.com they can be redirected to new.example.com. Or if someone goes to example.com/oldpage they can be redirected to example.com/newpage.
Beautify query strings. This also can make URL's more search engine friendly, easier to remember and presentable to real people. E.g. example.com/search.php?product=books can be turned into...
example.com/search/books or example.com/search/product/books
Htaccess can be used to accomplish a plethora of other things. These are just some common examples. Htaccess code can be generated for most of the above things using the htaccess code generator.