The name .htaccess isn’t a filename extension but a filename in full. For example, you wouldn’t create any such file named ‘file.htaccess’, because it’s simply called ‘.htaccess’. When you will place this file in any directory, it will take effect and get loaded through the software Apache Web Server. And the .htaccess file will show its instructed effect in all the files, subdirectories and overall the entire directory where it is being placed.
By using any of the trusted text editor like Microsoft WordPad, UltraEdit, and TextPad, you can create a .htaccess file. But note: Microsoft NotePad cannot be used.
An example code below showing what can be included in your .htaccess file.
AuthName "Name of Member’s Area" AuthUserFile /path/to/password/file/.htpasswd AuthType Basic Require valid-user ErrorDocument 401 /error_pages/401.html AddHandler server-parsed .html
The above example is fairly advanced. In it, password protection is enabled on the directory, it redirects to an error page which is customized to display as such in case of login failure by a user, and it also enables Server Side Includes (SSI) to be used with ‘.html’ files. That might sound like technical mumbo-jumbo, but fret not – it’s’ quite simple after you get some understanding, so bear with us.
As we mentioned before, this article contains specific examples that’s ready-to-use, you just need to copy them, and paste them, and finally customize them as per your business needs. Also, there is a detailed explanation of the examples so that you can understand what is the function of each line and its need for you.
Once the .htaccess file is created – ie, the code contained therein may look like the aforementioned (or it may contain a single line) – just upload it. Use a File Transfer Protocol (FTP) program to do this. There already should be one that you used for uploading your website content. IF you don’t have, you can get from many free websites like Download.com, WSFTP, or CuteFTP are all free and easy to use FTP clients.
When you upload your .htaccess file, it’s essential that you upload your file in the ‘ASCII’ mode. ‘BINARY’ and ‘ASCII’ are two different modes through which the data can be transferred, but while transferring .htaccess file it is very important that the your transfer your files using ‘ASCII’ mode only and not the ‘BINARY’ mode. It’s likely that by default the FTP software would be in ‘BINARY’ mode so find for ‘Transfer Type’ or ‘Transfer Mode’ in the menu option.
To upload your .htaccess file, use the directory where you want the file to show its effect. After uploading, use your browser to visit the directory and check whether it worked properly or not.
Note here, that after uploading the.htaccess file might not be visible on your web site’s file directory listings. But do worry, as it means that your FTP software or server is hiding it, which is not an issue.
There are possible chances of errors if file permissions are not correctly set on your .htaccess file. Only in certain servers, this type of problem occurs, but the permission of the file may be changed to ‘executable’ or ‘755’. This can be done with the software FTP, for that you need to find ‘CHMOD‘ option or a ‘File Permissions’ and input ‘0755’.
In case the .htaccess file doesn’t work, contact your web hosting service provider or system administrator and ensure that they’ve .htaccess enabled in your account. Use without permission is not allowed by some hosting companies. So, if the error persists, talk to your system administrator and ask for their help.