.htaccess Tutorial - Customized Error Message

August 8th, 2007

If you want to customize the error message to a vistor for a page was not found on your server, you can do it by adding following page to the .htaccess file.

ErrorDocument 404 /index.php

this line will redirect visitors to the /index.php on your server.

.htaccess Tutorial - Protect Images

August 8th, 2007

To prevent people from linking to the images on your server that abusing your bandwidth, you can use the mod_rewrite module to filter the unauthorized requests.

1. Activate Protection

Add the following lines to your .htaccess file to stop people from hotlinking to your .gif and .jpg files.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your_domain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
 

Replace your_domain.com with your domain name.

This starts by turning on the rewrite engine. Next, it checks the referer (where the request comes from).

If it did not come from your domain name and it is a request for a .gif or .jpg file, it will output an error message. Otherwise it will display the image as usual.

You can apply this with other file extension.

.htaccess Tutorial - Directory Listing

August 8th, 2007

When a web browser is pointed to a directory on your web site which does not have an index.html file in it, the files in that directory can be listed on a web page.

1. Enable/Disable Directory Listing

To have the web server produce a list of files for such directories, use this line,

Options +Indexes  

To have an error (403) returned instead, use this line.

Options -Indexes 
 

2. Listing Style

You can list file in  basic list style or fancy list style. A ‘fancy’ list including icons, file size, modification date and more. Following line is used for ‘fancy’ list style in the .htaccess file,

IndexOptions +FancyIndexing  

Use following line if you prefer a basic file list.

IndexOptions -FancyIndexing  

3. Ignore Files

If you don’t want the web server to list files with exention such as *.txt,*.jpg. Add this line to your .htaccess,

IndexIgnore *.txt *.jpg  

4. Modify Index File

To change the default index file, use this line

DirectoryIndex home.html  
 

First Page

August 8th, 2007

This is my first blog. I use this blog to file technical tipbids that helped me to resolve problems and acquire knowledge. I would like to share it with you, please feel free to leave me your comment.