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

How to setup custom error pages

Wednesday, December 10th, 2008

I guess you've all seen the standard error pages most web servers show when for example a page can't be found. If you haven't seen them before then you can't have been using the Internet for logn :D , but if you've seen a couple of them you know that they aren't that nice and not at all helpful.

The most common error page is the 404 Page not found error page and the standard error page is not at all helpful for a visitor. In most cases when a visitor see the standard page you'll lose a visitor since the will simply just hit the back button immediately. By setting up a custom page not found error page you can help your visitors to find what they are looking for or maybe interest them in some other part of your web site. You get at least a bigger chance with a custom error page…..

To do this you need a Unix or Linus based web server with Apache (most web servers are, but if you're hosted on Windows or something else you can switch to eXavier.com and get 10% off by using coupon code RS08Host).

Create a new directory in your public HTML folder (i.e. where all your public web pages are located) called something like /errorpages/ and create the error page you want your visitors to see. You can name the pages like 404.html for page not found errors, 403.html for access forbidden pages etc. If you're using .php pages on your web site you can of course name your error pages 404.php instead.

New text file called .htaccess in a text editor like wordpad or notes (don't forget the dot before the file name) and add the following text in it:

ErrorDocument 404 /errorpages/404.html

If you already got a .htaccess file in your public HTML directory then you should edit that one since it may contain important information, in that case just add the line(s) at the end of the file.

"ErrorDocument" will tell the server that it's an error document you're defining and the numbers after will tell the server which kind of error. You can have as many error documents as you like as long as you make sure you don't add the same error code twice. There are a couple of different error codes and some of the more common once are:

404 – Page not found
403
– Access forbidden, if you got a password protected page and someone enters the wrong password.
401
- Unauthorized, similar to the above code.
500
– Internal server error, when one of your scripts fail to deliver what it's supposed to deliver.

When you've created all error pages and filled in all of them on a separate line in your .htaccess file you just upload everything to your server. If you've done it correctly you should start seeing your error pages.

You can test your 404 page by visiting something like www.sampleaddress.com/lahdjkhafjksfhjashdf (i.e. a directory you know doesn't exist on your server).

How to avoid duplicate content penalties

Wednesday, November 19th, 2008

I guess you all know that search engines may see www.sampleaddress.com and sampleaddress.com as two different pages with the exact same content. Because of that your site may get duplicate content penalties from the search engine and in some horrible cases you may even get de-listed completely :(

By focusing all your traffic to just one of the options with or without www you may get higher pagerank as well since everyone will link to the exact same domain name. You may of course also gain other advantages too, but I'm not going thru them here….

If you got a Unix or Linux based web server it's quite easy to redirect all your traffic to the site with www (or without if you prefer that like we do at adv.erti.se).

Create a new text file called .htaccess (or edit the one that may already exist in your www or public_html directory) using a text editor like Notes or Wordpad. If you use Wordpress for your site you already got a .htaccess file in 99.99% of the cases, so then you just add the following lines of test:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sampleaddress.com$
RewriteRule ^(.*)$ http://www.sampleaddress.com/$1 [R=301]

If you're editing an existing .htaccess file you must make sure you don't add the first line if a similar already exists since that may cause errors. The above example will redirect all your visitors at sampleadddress.com to www.sampleaddress.com and also give the browser a 301 status message. The 301 status message is not really important for your visitors, but for search engine spiders since it means that the page they're looking for has moved permanently to it's destination at www.sampleaddress.com.

To do the redirection the other way around (i.e. from www to non-www) you just modify the code to be:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^sampleaddress.com$
RewriteRule ^(.*)$ http://sampleaddress.com/$1 [R=301]

What do the lines of text actually mean?

The first line is activating something called Mod_rewrite on your server letting your server rewrite URLs to a new destination. The second line is doing a logic test. If the host name (HTTP_HOST) is different from www.sampleaddress.com a rewrite should be done according to the condition on the third line.

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 :)



U DROP - I FOLLOW
Win 700 Entrecard credits

Recent Comments:

  • karl Allen: I found another niche search engine…. Gezzmo search :arrow:
  • AM: Good post. Looks like they’re trying to mimic Facebook’s corporate pages, or something similar. Seems...
  • luckyvic: :mad: You’re joking? Right? Elitextreme.com is is a leading carrier of biggest frickin’ ripoff,...
  • Latin Dating: Cool sale. I have planned to buying another new domains. Im still looking where to find a great deal I...
  • faisal majeed: So Twitter is awesome for Taking traffic to you website . It is very simple to setup and its a fun...
  • mikey: Aha – same email, with address, and I also use http://www.brother-store. co.uk/ Thanks for clearing this...

Recent Trackbacks:



© Copyright 1996-2009 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