Xics Web Host
Please Login or Register


PHP configuration using .htaccess

PHP configuration using .htaccess
The .htaccess file is a powerful tool for modifying your Apache configuration on a per-domain and even a per-directory level. Many content management systems rely on .htaccess files for configuring your site. You can also create your own .htaccess file manually.
Creating the .htaccess file

Your .htaccess file needs to be a plain text file. This means you need to make it in a text editing program capable of producing plain text files.
On a Windows machine, you can use Notepad, which is one of your built-in accessories.
On a Mac, you can use TextEdit. You must first open the TextEdit "Preferences" menu and, in the "New Document" section, select "Plain text." Then, you can start a new document in TextEdit for your .htaccess file.

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. This is because files that start with "." are considered to be system files.
Uploading your .htaccess file

You should upload your file to the exact directory you want it to modify. Typically, this will be your html directory (/home/00000/domains/example.com/html/), although you can upload it to any subdirectory on your server as well. See Using FTP and SFTP for assistance with uploading.

Once the file is uploaded, rename it to .htaccess exactly.

At this point, the file may disappear from your FTP display, because it now has the format of a system file. Many FTP clients allow you to view hidden files and folders if you enable that feature. Check your FTP client documentation for instructions.
.htaccess file priorities

A lower-level .htaccess file will override the settings in a higher-level one. For example, if you want to forbid directory indexing for most of your site but enable it for a specific directory, you can upload your .htaccess file to just that directory.

Similarly, .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. This means that you can set a PHP upload limit for one of your domains higher than it is on the rest of the server.

Finally, the order of directives within a file can matter for certain types of directives. Directives at the top are processed first.
PHP values

Most PHP values can be set in your .htaccess file as well as in your php.ini file. To use them in your .htaccess file, preface them with the following line:

For example, you could set:
php_value upload_max_filesize 16M

To check that your new PHP values have been implemented, use a PHP info page, and check the Local Value column.

// Show all information, defaults to INFO_ALL

Error Reporting

Put the following lines in your .htaccess file to enable complete error reporting. You can change the value from E_ALL to any desired type of error reporting:
php_flag display_errors on
php_value error_reporting E_ALL

Be sure to turn off this high level of error reporting once you've identified your issue, otherwise you may be displaying server information to your site visitors.

Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read


Quick Navigation

Client Login



Remember Me