Globally the Apache web server software is installed on almost two-thirds of all servers, and with Apache comes the incredibly powerful but very mysterious.HTACCESS file.
Most people only use the file for simple password protection, but it can be used for much more than that.
This article will help to show some of the possibilities that lie within your site.HTACCESS file
One of the neat features of the. htaccess file (please note, the filename must always be in lowercase), is that file can be edited on with almost any text-based editor (such as the Windows Notepad).
Controlling if files are downloaded or Opened in the Visitors Web Browser
With the following code snippet, the site owner can determine how the file is downloaded.
This example (with files as.gz,.pdf,.zip and.rar) forces the file to be downloaded directly rather than having the browser attempt to open the file in the browser window.
ForceType application/octet-stream
Allow only certain users access to the server based on their IP address
The following code snippet allows only users of a certain IP address (in this case 27.101.84.200) to access the server.
All other users are rejected.
order deny, allow
allow from 27.101.84.200
deny from all
Deny Access to certain Files in The Mysterious.HTACCESS file
The following code snippet determined what files can be accessed. In this example, all access to files starting with the “.” symbol is declined. This will stop people from accessing (or viewing) your. htaccess file
deny from all
Allow Server Side Includes on your Site
This code line will ensure that files, which contain server Side Includes (SSI), will also get processed if they carry the.HTML file extension
Add handler server parsed.HTML
Error Handling
When an error occurs on your website, such as a person trying to access a file that does not exist, then the. htaccess file can display a “customized” error page for that particular error:
For example:
Error document 404 /404error.HTML
Now when a user tries to access a file that causes a 404 error to be generated, the. htaccess file will now load and display the HTML file called 404error.HTML
Please Note: This file must live in the root directory of your website’s structure (i.e. in a LINUX installation, in your /public_html/ folder).
Sometimes Microsoft Windows has a problem with filenames that have a “.” symbol as the first name.
To overcome this simply upload the file as something different and then rename the file when it’s on the server.