Complete guide of htaccess file

Today I will guide you about basic usage and implementation of .htaccess file.

.htacces file is a distributed configuration file of your webiste which are running on the Apache Web Server software. It is used to change configuration of your web on a per directory basis. You can use php_value to change php setting in .htaccess file like we use php.ini file.

Some other use of .htacces file:

  • Cache Control: By making changes in .htaccess file you can control cache of your website.
  • Authentication: .htaccess file is used to specify the security restriction to any file or directory.
  • REWRITING URLS:.htaccess file can be used to rewrite your website’s bad url.
  • CUSTOMIZED ERROR RESPONSES:By .htacces file you can change your 404 eroor page. for example HTTP 404 Not Found then you can change that error page like: ErrorDocument 404 /pagenotfound.html

Where will I find the .htaccess file?

An .htaccess file can be found in every directory of your web. But normally it is located in root directroy of your web like www or in public_html directory in your web and in all subdirectories of your web(/sitename) too.

Why can’t I find the .htaccess file?

Most of the cpanel hide their files which are started with a (.). So to check that files just go into setting in cpanel and enbale show hidden files option. Then you will be able to see all(.) extensions files.Some time if you don’t see that file it means .htaccess file is not create yet so you can create that by clicking on create new file option in cpanel. Remeber you will have to save that file only with the name .htaccess. I will show with the help of screenshots that how can you create .htaccess file in cpanel.

Step by step guidance to view and to create htaccess file:

Please login into your cpanel and go to Filemanager. Then go to public html folder which is root of your webiste or the folder where your website files are stored. You will see list of files there. There can be a file named .htaccess. If you have FTP accounts then you can login into FTP account check .htaccess file there or can creat a new file. Here i will show you .htacces file in cpanel.

1. First there is no htaccess file.Here it is hidden right now.

2. How to view hidden files. Please follow the given screenshots.

Step One:

Step Two:

Step Three:

3. If no hidden file available or there is no .htaccess file created yet. Here are the complete steps to create new .htaccess file.

Step One:

Step Two:

Step Three:

4. When file is created you will see that file in root folder Now you can edit that file to put your htacces code.