Xavier Media
Xavier Media Blog All you need to know as a web site owner, blogger or webmaster
Subscribe to our feed:

 Subscribe in a reader

Subscribe by email:
Enter your email address to subscribe to this blog by email:


Search this blog:

Archive for the ‘.htaccess’ Category

Protect your pictures and prevent bandwidth theft

Sunday, January 27th, 2008

If you got a camera to improve your posts (like I wrote in Five things all bloggers need) then you will sooner or later find a jerk or two that’s stealing your work and using it on their own blog/web site. As a blogger you need to protect the content you’ve worked so hard for and you need protect your bandwidth from bandwidth theft. Unfortunately it’s not always so easy, but to protect your pictures from “hotlinkers” (people using content hosted by you as their own without giving you credits) there’s an easy to use way to make their life a little bit harder.

If you’re site is hosted on a Un*x server you can use something called .htaccess to make hotlinking almost impossible. I used this method when Xavier Media had a free Midi file archive at www.xaviermedia.com/midi/ so I know that it’s working :)

Create a text file called .htaccess.txt using Notes or Wordpad:

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

The first line turns the Rewrite Engine so this example will work, the second line will allow your own domain name to link to your pictures and the third line will allow empty referrals. [NC] on the second line means No Case and is used when you need SaMPleAddreSS.com to be the same thing as sampleaddress.com :D

In the fourth line you set the file extensions you want to rewrite and the image to display instead of the hotlinked images. Please note that the prohibited image is called .jpe instead of .jpeg so it will show in the visitors browser (otherwise you create an infinite loop which will case no image at all to show up :( ).

If you know the domain names of some bad guys hotlinking to your valuable stuff on your server you can use this code in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+.)?facebook.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?blogspot.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?myspace.com/ [NC]
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/prohibited.jpe [L]

You can block as many domain names you like. Just make sure you add [NC,OR] at the end of each line except for the last RewriteCond line which should only have [NC] at the end.
When you’ve saved your work simply upload the file to your server (the www directory or maybe the directory where you keep your pictures). If you called your .htaccess file .htaccess.txt you need to rename it to .htaccess when you have uploaded the file to your server.

If you got other files you need to protect this example works with any other file type. I mentioned in the beginning of this post that I used it on midi files :)

How to make money from missing pages

Saturday, January 12th, 2008

All web sites move pages to new locations, pages are removed from sites because they are old or outdated, visitors sometimes type the wrong URL to get to a page and I think I can list about 10 other reasons for users to end up with a 404 Page Not Found error. If you haven’t done anything with your hosting account all those visitors will just see the standard error page which is really boring and not helpful at all. On most hosting accounts you can do something about that and also earn some money from it!

Start by creating a text file called .htaccess in your web directory (that’s where you keep your main index.html or index.php file). I use Notes or Wordpad to edit my .htaccess files (or nano if I’m connected directly to the server).

The file should look something like this:

 ErrorDocument 404 /404.php

If you already got a file called .htaccess in your hosting account you should simply just add the above line of text into that file (don’t over-write your existing .htaccess file since it may contain important information).

Now create a new file called 404.php (you can of course name the file anything you like, but I used 404.php in my .htaccess file so that’s what I’m going to use). You can use Notes or Wordpad for this file too. Fill in the following text in your new 404.php file:

<?
Header("HTTP/1.0 404 Not Found");
?>
<!-- Page content goes here -->

At <!– Page content goes here –> you simply add some text telling the visitor that the requested page wasn’t found on your server. Also give the visitor some advice on how to find the requested information (give the visitor a possibility to search your site for example of add a link to a site map).

Since the visitor is at your site he must be interested in your products or services, so don’t forget to tell the visitor about your products and services. Next time when a users see the 404 error page he will hopefully stay at your site a little bit longer instead of using the back-button in the browser immediately the 404 error shows up. Not everyone will become your customers, but at least enough for this to pay off :D




U DROP - I FOLLOW
Win 700 Entrecard credits

Recent Comments:

  • marie31: HEy! This is so cool! I wanna join too!!! :)
  • Steven Walling: Regarding your third suggestion, I think http://www.aboutus.org/Ba dge_for_website_owners is what you...
  • sunzhine4you: Wow, this is a very cool contest! I enjoy reading your post, they are very educational. I look forward...
  • WELLY: it’s a nice site with full of information and content… Greetings, jump to my blog please
  • Hazel: Good luck to us ~
  • Khyle: Your events rocks and i love your post regarding php. Incidentally, I would be enrolling a php short course...

Recent Trackbacks:



© Copyright 1996-2008 Xavier Media. All rights reservered.
Contact us | Support/help | Privacy Policy | Company Info | SiteMap
The World According to Xavier | Xavier in the World | the Xavier Media blog