How to Use the .htaccess File

The .htaccess file is a small and powerful tool that controls many aspects of your website. It is possible to modify your Apache configuration on a per-domain and even a per-directory level by it. Many systems including TomatoCart rely on .htaccess files for configuring your site. Things like redirects, enabling compression, rewriting urls for seo, enabling client caching and more can be achieved by adding some code to this little file. But, some general users may don’t know how to use it. So, I will describe it in great details in this article.

Where to find the .htaccess file?

Typically the .htaccess file will be on the “root” level or the “www” folder. But, it is important to note that the .htaccess file is by default a “hidden” file.  If you familiarity with the use of FTP, you could find it in the ftp tool. You could also find it by the file manager tool in your host cpanel. Most web hosts will provide an option to “see hidden files” when first opening the file manager. It is also worth noting that there can be no .htaccess file, or several. In theory every folder can contain one. If there isn’t the file, you could also create your own .htaccess file manually.

Creating the .htaccess file

In fact, your .htaccess file just be a plain text. So, you just need to create a text file with any text editing tool such as Notepad or sublime etc. When you save your document, make sure you name it htaccess.txt, or something similar. If you save it as .htaccess, your computer will hide the file because files that start with “.” are considered to be system files.

Uploading your .htaccess file

After creating the file, you should upload it with ftp tool to the exact directory you want to modify. Generally, this should be your public html directory so that the configurations in the file is used for your whole web site. Once the file is uploaded, don’t forget to rename it to .htaccess.

How to use it?

.htaccess files override PHP settings from your higher-level vhost.conf and/or php.ini files, unless overriding is disallowed in these higher-level files. So, you could change the server or php settings by modifying it.

  • Always have a working functioning copy of your .htaccess file
  • Every time you make a change to this file you should save the file, then go to test your website to confirm it works correctly. Doing this will save you many problems.
  • If you do screw something up, just copy and paste the contents of your backup copy into the .htaccess file and save it again and your website will work as it did before.

— Php Values

Most PHP values can be set in your .htaccess file as well as in your php.ini file. Our hosting environment does not allow updating PHP directives or variables in .htaccess, so please make sure to not use the php_value directives to edit values for PHP. You can use the php.ini file only to do that. After that, you could check the new setting via the php info page:


Examples of what NOT to do:

To enable and change the level of error reporting for php, you could add following lines into .htaccess:

php_flag display_errors on
php_value error_reporting E_ALL

On our environment, you need to do this in the php.ini file and add the lines:

display_errors on
error_reporting E_ALL

— Changing the default index page

You could also changing the settings for web server. For example, if you wish to replace the default index.php with home.html, you just need to add the following line into the .htaccess:

Directory Index home.html

As you can see, it is very powerful to use the .htaccess file for your website. You could find more useful directives in official documents – Apache HTTP Server Tutorial: .htaccess files

Try it!

Looking for quality TomatoCart Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , | Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

6 Comments on How to Use the .htaccess File

  1. subhash acharya says:

    after creating .htaccess file where should i paste the code?

  2. Ben K says:

    I don’t think mod_rewrite is loaded on my php install. How do i enable it?

  3. DDhillon says:

    Is it possible to have .htaccess file on ASP VPS?

Leave a Reply

Your email address will not be published. Required fields are marked *