Heather’s Blog

Love is like playing the piano. First you must learn to play by the rules, then forget the rules and play from your heart

Archive for the ‘htaccess’ Category

What if another web site is stealing your images and your bandwidth by linking directly to your image files from their web site? This can prevent this by adding this to your .htaccess file:

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

Replace yourdomain.com with your actual domain name. With this code in place, your images will only display when the visitor is browsing http://yourdomain.com. Images linked from other domains will appear as broken images.

If you’re feeling particularly nasty, you can even provide an alternative image to display on the hot linked pages — for example, an image that says “Stealing is not nice … visit http://yourdomain.com to see the real picture that belongs here.” Use this code to accomplish that:

RewriteEngine On
rewriteCond %{HTTP_REFERER} !^$
rewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
rewriteRule \.(jpe?g|gif|png|bmp)$ dontsteal.gif [L]

This time, replace yourdomain.com with your domain name, and replace dontsteal.gif with the file name of the image you’ve created to discourage hot linking.

Here is my image
dontsteal.gif

Check out other post related to .htaccess here

Click here to buy me a coffee If you liked this post (only $3.50)

You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to ‘index’ files though. Using .htaccess you can set ladida.blah to be your index file if you want to!

Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).

Example:
DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm

For other post on .htaccess files check out these post

Click here to buy me a coffee If you liked this post (only $3.50)

In my continued love for the wonderful .htaccess file here is a great way to create your own custom error pages such as “404 document not found” please remember that .htaccess files only work with Linux/Unix servers.

Open up your .htaccess file and place the following line in it, please note that you can name your 404 page what ever you want it doesn’t have to be 404.html

ErrorDocument 404 /404.html

So instead of having a boring white page like this

404

You can create what ever you like such as something I have here

Here is a list of the most common error pages

401 - Authorization Required
400 - Bad request
403 - Forbidden
500 - Internal Server Error
404 - Wrong page

For other post on .htaccess files check out these post

Click here to buy me a coffee If you liked this post (only $3.50)

Redirects w/ htaccess

Jan-23-2006

I love htaccess files for so many reasons. This is one of them, many times I will be surfing the net and often come across pages that say you are now being redirected to to this page. Although its not really a problem it can be rather tacky looking. Why not drop a htaccess file into your root directory with something similiar to this written inside. This way your viewers will automatically go where you want them, and it’s instant.

Redirect /oldpage.html http://www.yourdomain.com/newpage.html

Need help with creating your htaccess file read here for another topic

If your server is Windows based you need to stick with the good old redirect page placing the following into the page

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Your Title</title>

<meta http-equiv=”refresh” content=”5;URL=http://yourdomain.com/newlocation.html/”>
</head>

<body>

<br>
You are being redirected to the yourdomain.com newlocation.<br>
<br>
If your browser is not redirected withing 5 seconds, please <a href=”http://www.yourdomain.com/newlocation/”>click here</a>.
</div>
</body>
</html>

Click here to buy me a coffee If you liked this post (only $3.50)

You don’t know how many times I have read problems in forums with users who have a php script that allows them to upload files but they get errors that say filesize is too big or corrupt. The problem is, by default php has a upload limit of 2mb. To overide this we can use the .htaccess file

Before doing this as well with any modifications to any files always make sure to have a backup of your original file.

Add this line in your htaccess file

php_value upload_max_filesize 10M // max size in Mb

Don’t have an .htaccess file?

You don’t need any special program or hardware to create an htaccess file. In fact, all you need is a regular, simple text editor such as Notepad.

Now the tricky part is saving the file. The htaccess file is a no-name filename with an eight letter extension. “.htaccess” When you save files in a text editor, it will usually add a default extension to files, so you might end up with… “.htaccess.txt”

Here is how you fix this problem : File Save As… In the FILE TYPE box, choose ALL FILES In the FILE NAME box, type in “.htaccess” And be sure you used quotes around the filename when you typed it in.

If that doesn’t work, your FTP program should let you do a RENAME on a file to make it right.

Click here to buy me a coffee If you liked this post (only $3.50)