How to set up custom .htaccess files for PHP settings

This article describes how to use custom .htaccess files to control PHP settings for your web site.

The information in this article only applies to certain types of hosting accounts. To determine whether or not the information below applies to your account, please see this article.

Setting up a custom .htaccess file

You can use directives in an .htaccess file to control many PHP settings. Additionally, you can set up one or multiple custom .htaccess files to define how your web site functions. For example, you might have a custom file in your public_html directory for your web site's main pages, and a separate custom file in your public_html/images directory for your web site's image files.

To set up a custom .htaccess file, follow these steps:

  1. Log in to your A2 Hosting account using SSH.
  2. Use a text editor to create an .htaccess file in your web site's document root directory.
    Alternatively, if you want to set PHP settings for a specific subdirectory, create the .htaccess file in that subdirectory.
  3. For security reasons, the .htaccess file contents should not be visible to the public. To do this, add the following lines to the .htaccess file:
    # Prevent Apache from serving .ht* files:
    <FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    </FilesMatch>
  4. Save the changes and exit the text editor. You are now ready to add specific PHP directives to the .htaccess file. For more information about how do this, please see these articles.

More Information

To view a complete list of PHP directives, please visit http://www.php.net/manual/en/ini.list.php.

Article Details

  • Level: Intermediate

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.