When you choose to use a “pretty” permalink structure, by default WordPress should create the .htaccess automatically and add the necessary code there.
However, if that doesn’t happen, it will display a message saying “You should update your .htaccess now” and you need to manually create the file.
To do this, just open your preferred text editor and add the code below.
Then save it as .htaccess (but make sure that it doesn’t have a .txt extension) and upload it in the root directory of your website.
If you already have a file there, you should check its contents before overwriting it.