Afternoon Fellow Geeks,

There are so many HTACCESS tutorials tips and tricks out there so I thought I would give you a run down of my favourite ones in no partiuclar order. SO lets do this.

The first tip I am going to show you is how to avoid people stealing images of your site and using them for themselves this is called hotlinking, we can have a little fun with this one to, ok here we go.

The following code below stops hotlinking, and the great thing about this code is you can add an alternavtive image to be displayed, hence I said this could be fun, so just add a location at the bottom of the code to the image you want to be displayed. :)

RewriteCond %{HTTP_REFERER} !^http://(.+.)? [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*.(jpe?g|gif|bmp|png)$ http://yourimage.gif [L]

I really like that example works really well, OK onto the next one.

Another favorite of mine is being able to customise my error pages weather a 404 or a 500, the following code below will help you achieve this.

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

As you can see each page has to be created in this example I have create a folder called error, within this folder I then create my custom errors, they can be what ever extension you wish.

Lets look at downloading now, and how we inforce this. Sometimes, when clicking on media files, the browser wants to play or stream it directly from itself. Using the code below you can force the server to download the media.

AddType application/octetstream.mpg
AddType application/octetstream.wmv
AddType application/octetstream.mp3
AddType application/octetstream.avi

I like my server to be nice and fast so lets look at caching certain file types, the below code will help you do this.

<filesmatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set CacheControl "maxage=2592000"

Security next we need to make sure our site is hacker proof well at least make it hard for them, one section I always like to add is blocking of my htaccess file making it so it cannot be used. The following code will do this for you.

<files .htaccess>
order allow,deny
deny from all

OK people this is all for today now doubt I will add more code as and when I either I event new ones or find some good examples, hope you enjoyed.