Underground Worx Hosting

Diversity, Ingenuity and Enthusiasm

.htaccess Tutorials

.htaccess Tutorials Homepage

Directories

Prevent access to PHP files

Prevent requests with invalid characters

Error Documents

Redirects

Password Protection

Deny Visitors

Ensure media files are downloaded instead of played

Associations for Encoded Files

Hot Link Protection

Blocking offline browsers and "bad bots"

Forcing scripts to display source code

Add MIME types

Enable SSI

Enable CGI outside of cgi-bin

Timezone

Server Signature

Other Resources

Administrator User Guides







Apache Web Server Tutorials

  .htaccess

UWX Hosting Navigation

UWX Hosting Homepage

Hosting Plans

Tutorials

Contact

Current Hosting Clients

SMCGAoA

WV Minutemen

M & S Services

Tom's Landscaping

Underground Worx Companies proudly supports the SMCGAoA, and provides contribution by donating all internet services free of charge.

What is .htaccess?

An '.htaccess' file is an Apache Web Server configuration file. '.htaccess' is the full file name. It is not a file extension. For instance, you would not create a file called, 'file.htaccess', it is simply called, '.htaccess'. This file will take effect when placed in any directory which is then in turn accessed via the Apache Web Server. The file changes the settings over the entire directory it is placed in and all files and subdirectories under it.

You can create an '.htaccess' file using any good text editor such as Gedit, TextPad, UltraEdit, WordPad or an other similar text editor. Take note that you cannot use Microsoft NotePad.

Here is an example of what you might include in an .htaccess file:

AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html

This is a fairly advanced example: it enables password protection on the directory; it offers redirection to a custom error page if a user fails to login correctly; and it enables SSI (server side includes) for use with '.html' files. '.htaccess' files are very simple once you gain a basic understanding and these tutorials provide examples which are ready to go - simply copy, paste and customize. Examples are explained line by line so it is clear exactly what each line does and why you need it.

Once you have created an '.htaccess' file, which may look similar to the one shown above (or may simply contain one line), you need to upload it. This should be done using a FTP program. You should already have one which you will have used to upload your website content. If not, many are available free of charge and we can recommend 'FileZilla'.

When uploading your '.htaccess' files, it is very important you upload the file in 'ASCII' mode. 'ASCII' and 'BINARY' are different methods of transferring data and it is important '.htaccess' files are transferred in 'ASCII' mode and not 'BINARY'. It is likely your FTP software will default to 'BINARY' so look for a 'Transfer Mode' or 'Transfer Type' option in the menus.

Upload the '.htaccess' file to the directory you would like it to take effect over. Now visit this directory using your web browser as you would for any other document on your web site and check that it has worked correctly.

Note, when you upload your '.htaccess' file it may not appear in the directory listings for files on your website. Do not worry; this means your server or FTP software is hiding them which should not be an issue.

A possible cause of error is if the file permissions on the '.htaccess' file are not set correctly. This only occurs on certain servers, but you may like to change the permissions on the file to '755' or 'executable'. You can do this with your FTP software, look for a 'File Permissions' or 'CHMOD' option, and input '0755'.

Some web hosting companies do not allow use of '.htaccess' files without permission. If your '.htaccess' file does not work, you should contact your system administrator or web hosting company and ensure they have enabled '.htaccess' within your account. If errors persist, contact your system administrator for advice.