The Beauty of .HTACCESS

The Beauty of .htaccess

 

    .htaccess is short for Hypertext Access, is a configuration file for use on web servers running the Apache Web Server software. Using htaccess file we can alter the configuration of the Apache Web Server software like Redirect Functionality, Password protection, disabling directory listing, setting server time zone, changing server signature etc 

What is an .htaccess file?

     The file itself is just a small basic text file and can be edited, via notepad, or your hosts file manager, thru c-panel redirects. In general, you should only use .htaccess files when you don’t have access to the main server configuration file. 

Below is some usage of htaccess files in server:

  • Authorization, Authentication: .htaccess files are often used to specify the security restrictions for particular directory, soothe filename “access”. The .htaccess file is often accompanied by an .htpasswd file which stores the user name and their passwords.
  • Custom Error Pages for Better SEO : Changing the page that is shown when a server-side error occurs, For example

ErrorDocument 400 http://localhost :7001/MY_PROJECT/error

  • Mod_Rewrite : Using rewrite actual URLs can be changed to other name
  • Cache Control: .htaccess files allow a server to control user agent caching used by web browsers to reduce bandwidth usage, server load.

How to activate an .htaccess file

If you have access to the server settings you can edit the configuration to allow the .htaccess file to override standard website configs. Open the apache2 default host configuration file.

NB: You will need sudo privileges for this step.

Once inside that file, find the following section, and change the line that says AllowOverride from None to All. The section should now look like this:

 

After you save and exit that file, restart apache.

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