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

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.

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.

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.

  • 57 Users Found This Useful
Was this answer helpful?

Related Articles

How to change the date.timezone value in PHP?

If your PHP scripts do not show the correct time, the reason is that most probably your hosting...

Creating a simple, safe contact form

If you've ever wanted a feedback or contact form on your website, you may find the following code...

Cron jobs

A 'cron job' is an automated task that can be set up within your cPanel. This will typically be...

Disabling catch-all email

If you wish to disable the default catch-all email address - i.e. you will only receive email to...

File permissions

There are a number of file permissions, which can be used for a variety of different purposes,...