top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is .htaccess and how to use .htaccess?

+1 vote
433 views

.htaccess is a configuration file for use on web servers running the Apache Web Server software.
When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server',
then the .htaccess file is detected and executed by the Apache Web Server software.
These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as 'content password protection' or 'image hot link prevention'.

How to use .htaccess:-
.htaccess is the filename in full, it is not a file extension. For instance, we would not create a file called, 'file.htaccess', it is simply called, '.htaccess'. This file will take effect when placed in any directory which is then in turn loaded via the Apache Web Server software. The file will take effect over the entire directory it is placed in and all files and subdirectories within the specified directory.
We can create a .htaccess file using any good text editor such as TextPad,UltraEdit, Microsoft WordPad and similar (we cannot use Microsoft NotePad).

Here is an example of what we might include in a .htaccess file.

AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html

This is a fairly advanced example:
it enables password protection on the directory; it offers redirection to a custom error page if a user fails to login correctly; and it enables SSI (server side includes) for use with '.html' files. Please don't be put off, it's very simple once we gain a basic understanding and this article provides examples which are ready to go - simply copy, paste and customize. Examples are explained line by line so it is clear exactly what each line does and why we need it.

Once we have created a .htaccess file, which may look similar to the one shown above (or may simply contain one line), we need to upload it. This should be done using a FTP (file transfer protocol) program. We should already have one which we will have used to upload our web site content. If not, many are available free of charge from web sites such as 'Download.com' and we can recommend 'CuteFTP' and 'WSFTP'.

When uploading our .htaccess files, it is very important that we upload the file in 'ASCII' mode. 'ASCII' and 'BINARY' are different methods of transferring data and it is important .htaccess files are transferred in 'ASCII' mode and not 'BINARY'. It is likely our FTP software will default to 'BINARY' so look for a 'Transfer Mode' or 'Transfer Type' option in the menus.

Upload the .htaccess file to the directory we would like it to take effect over. Now visit this directory using our web browser as we would for any other document on our web site and check it has worked correctly.

Note, when we upload our .htaccess file it may not appear in the directory listings for files on our web site. Do not worry; this means your server or FTP software is hiding them which should not be an issue.

A possible cause of error is if the file permissions on the .htaccess file are not set correctly. This only occurs on certain servers, but we may like to change the permissions on the file to '755' or 'executable'. We can do this with our FTP software, look for a 'File Permissions' or 'CHMOD' option, and input '0755'.

If our .htaccess file does not work, you should contact your system administrator or web hosting company and ensure they have enabled .htaccess within your account. Some web hosting companies do not allow use without permission.

References

For more information http://www.htaccess-guide.com/
posted Jun 23, 2014 by Vrije Mani Upadhyay

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button

...