Changing the .htaccess filename in Apache
Posted April 17th, 2008 in Apache
Apache allows the use of .htaccess files which can change certain configuration options in a per-directory basis. By default .htaccess files are named .htaccess but it is possible to use a different name either for the whole server, or on a virtual host by virtual host basis. This post looks at how to change the filename used.
Please note that the use of .htaccess files can be switched off and may not be available on your web host's platform. When enabled, the default .htaccess name is usually used but it may be different for your host. It always pays to check your web host's documentation to see what is and is not available.
I am a website developer and use .htaccess files to set up rewrite rules, permanent redirects, specify particular PHP settings and so on. Sometimes the settings in these files need to be slightly different on my development machine from what is set on the production server. In these instances, it is useful to have two different copies of the .htaccess file: one for each server. That way there's no chance of accidentally overwriting the production server's copy with a local copy, because the names are different.
To use a different name from the the default, use the AccessFileName directive in the virtual host's <virtualhost> settings. For example, where the setting is in bold:
<virtualhost> ServerName www.example.local DirectoryRoot /var/www/www.example.local AccessFileName .htaccess.testing
</virtualhost>
The above virtual host would now use .htaccess.testing as its .htaccess file, if it exists. All you need to do is to reload Apache and the new setting will take effect.
Related posts:
- Password protect a directory with Apache (Tuesday, June 29th 2010)
- Get Apache to parse .html files as PHP (Sunday, January 10th 2010)
- Aliasing images to a remote server with .htaccess (Saturday, April 19th 2008)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

