Wednesday, February 04, 2015

The .htaccess File and MAMP PRO

The .htaccess file is an Apache Server configuration file. Many content management systems use them. They are used for custom configuration of Apache Server for a host. Changes to the access of your .htaccess file can be made in the General section of the Hosts tab.

Enabling the .htaccess File

By default your MAMP PRO Apache Server is configured with the .htaccess file enabled. The  [ AllowOveride All ] directive allows any directive with .htaccess context to override the Apache Server configuration.

Set the AllowOverride directive to [None] if you wish to disable your .htaccess file.

More information concerning the AllowOverride Directive can be found at the Apache Server website.

The .htaccess File Is Hidden

You will not see a .htaccess file in the Mac Finder because it is a hidden file. An easy way to see if a .htaccess file exists in a directory, or open the file itself, is by using the text editor TextWrangler. From TextWrangler go to File -> Open.  Click Show Hidden Items. You will now see if a .htaccess file is in the directory, and open it if you wish.

Wordpress and .htaccess

Many content management systems will dynamically create .htaccess files to make customisations to Apache Server. One example are permalink settings in WordPress.

Wordpress will create a .htaccess file when you set your permalink settings to anything other than Default. You will not be able to see your blog pages if you have your AllowOverride set to None and your permalink settings set to anything other than Default.

The following is the content of the .htaccess file that is created when you set the permalink to Day and name.

Create Your Own .htaccess File

You can also create your own .htaccess and make your own Apache Server customisations. Use a text editor such as TextWrangler to create a .htaccess file. You may get a warning that you are about to create a hidden file when you do. The following .htaccess file directive will make Apache Server first look for MyCoolIndex.php instead of the customary index.html and index.php.

Add the following line to your newly created .htaccess file:

DirectoryIndex MyCoolIndex.php index.html index.php