↩ Advanced Users

The .htaccess file

What is "the .htaccess file"?

The .htaccess file is one of the most powerful tools available to you. Essentially, it's nothing more than a text file called ".htaccess" that contains a list of commands, but used correctly you can achieve a number of things with .htaccess

The basic principle of .htaccess is that any commands given apply within the directory the file resides in, as well as any subdirectories below it.

Example: The command "Options -Indexes" turns off 'directory browsing'. If we place this command in a file called '.htaccess' inside /home/username/www/ directory browsing will be turned off for not only 'www', but also ALL directories within 'www'. In order to turn it back on for a specific directory, you would need place an .htaccess file within it, with the command "Options +Indexes".

By default we turn directory browsing off for MyHost clients using this method.

Common Uses

The full scope of .htaccess files is greater than we can go into here, however we'll take a quick look at a couple of the more common uses. You'll find many good .htaccess tutorials on the net that expand on these.

Change index page

Perhaps you'd like your index page to be mymainpage.html instead of index.html?
The Command
DirectoryIndex mymainpage.html

Redirecting pages

Changed the name of a file or directory, but would like to seamlessly redirect your visitors?
The Command
Redirect /oldfile.html http://www.yoursite.co.nz/newfile.html

Redirection and a few other common .htaccess commands, including password protection and custom error pages, are now available through your cPanel. These functions create and/or edits your .htaccess files for you, but you're still welcome to edit them yourself.

Can't see .htaccess in your FTP client?

.htaccess is a hidden system file, however most common FTP clients do allow you to view, edit and upload .htaccess and other hidden files to the server.

By default this feature is typically turned off, so you will need to do the following (or similar) in order to enable it.

WS_FTP
Go to the main 'WS_FTP Sites' connect screen.
Highlight your site (single-click).
Click the Properties button.
Click the 'Startup' tab.
Type -a into the Remote file mask box.
Click OK and reconnect to your site.

CuteFTP
Go to File > Site Manager.
Highlight your site (single-click).
Click the Edit button.
Check the Enable Filter box.
Click the Filter button.
Select Enable remote filters.
Type -a in the Remote filter field.
Click OK and reconnect to your site.

If you still can't view your .htaccess files, the 'File Manager' in CPanel allows you to do so.