.htaccess Setup

.htaccess allows you to do many different things with your hosting account. Some that override the general server configuration, some that provide password protection, and even some that can allow you to selectively block IPs, countries, or whole regions from seeing your website.

When talking about .htaccess please note the preceeding dot (.) before the word htaccess. This means that .htaccess is not a file in the normal sense, it's actually an extension (like .doc, .txt etc..). The server treats this differently to other files in that it looks it it first before it does anything else. This means that, configured with certain rules, .htaccess can govern how a directory, or your entire website works.

In order to create an .htaccess file we have to do something strange (in Windows anyway). In Windows, open notepad, and save the file to your desktop as htaccess.txt (sometimes notepad will append the .txt regardless). Note: Saving this file as .htaccess will not work in Windows.

Re-open the file in notepad as htaccess.txt, now we can do all sorts of things. Here are a few examples:

All rules are usually single lines of text, and must be copied exactly as they are presented.

Directory Index Listing

Definition: a rule to allow a visitor to index the contents of a directory on your website (this is usually forbidden by default) is done by adding:

Options +Indexes

Enabling PHP5 (php5 enabled servers only on 3dpixelnet hosting)

Definition: a rule to force .php to be parsed using the php5 engine vs the default php4 engine is done by adding:

AddHandler application/x-httpd-php5 .php

Register Globals

Definition: a rule to allow the user of global variables via the register_globals parameter (disabled by default) is done by adding:

php_value register_globals 1

Block IP Addresses

Definition: a rule to prevent certain IP addresses or IP ranges from accessing your website or directory is done by adding:

order allow,deny
deny from 192.168.1.1

or..

order allow,deny
deny from 192.168.1.1/24

Save the file as htaccess.txt as discussed above. Open your FTP client and connect to your website. Now, depending on which directory on your website you would like this feature to be enabled for, determines where you put the .htaccess. .htaccess affects ALL directories below the directory you install the .htaccess into. For example if you want EVERY directory on your site to be listed the .htaccess would be put into httpdocs, your web root.

Copy the htaccess.txt to the required directory, and actually on the FTP site, rename the htaccess.txt to .htaccess

Nearly all modern FTP clients have the ability to rename files on the remote server - please check through the options on the FTP program you are using if this is not immediately obvious.

Browse to the directory you have installed the .htaccess to in your webbrowser, and the result should be obvious; in our example, the directory listing.

Please note that should you edit any of the rules, please keep a copy of the htaccess.txt on your own computer, remove the .htaccess from the server and reupload and rename as above.