Apache 404 ErrorDocument Configuration .htaccess

Strongly recommended book
Hi Guys,

Well I though I must share this with you because it is such a simple thing to know but still lot of us don’t know which config property we work with to achieve 404 redirects.

This should be a habit of yours when working as a Web developer that no links are broken what if one or two of them are and user see weird apache errors. Better thing will be to redirect to say a sitemap of your website or any other informative page rather than displaying “404 not found”.

If annoying for your website visitors as well when they see this.

Alright now let me talk about prerequisites to configure this properly.

  1. Your hosting company should support .htaccess file
  2. AND you are able to change .htaccess file

Now that the boring part is gone, let me give you an example

Copy this link below and paste it in your browser and then see what happens

http://jaspreetchahal.org/isstupid.html

It should display a lot of info and should tell you that URL is not found and you can browse to other interesting places on my website.

Now the setting

Open up your favourite text editor and then open .htaccess file that lives in root folder of your website (if it does not exist then create one) and add this line to that file

 

  1. ErrorDocument 404 /filenotfound.html

Now create a file named filenotfound.html in your root folder of you website and add whatever information you would like to add-in and then try to goto a URL that does not exist in your website.

That’s it. You’ve just configure your permanent 404 error document for your website.

Please let me know if you have questions

 

Cheers

 

 

 

 

Search Terms:

Jaspreet Chahal

Self-confessed Max Payne and Howzat Cricket game addict. Big fan of Dharmendra, Keanu reeves & Lawrence "Larry" Page. I love my Wife, my son and bit of geeky stuff. I started falling in love with Blog'in last year. Writing is tending out to be fun. I write on situation I was in thus my post always travel around web development stuff. I hope you enjoy my posts.

More Posts - Website

Follow Me:
TwitterFacebookPinterestYouTube

Speak Your Mind

*

CommentLuv badge