scriptygoddess

08 Dec, 2002

Friendly error pages using PHP and .htaccess

Posted by: amy In: Admin-type scripts

I know that we've posted about .htaccess files and friendly error pages before, but after some questions from my spouse, I decided to write up something more along the lines of a package of scripts. It contains a bit of optional logging, if you want to keep an eye on the details of your errors, but that can be turned off if you want.

My full entry (although not much longer than this) about the package is available here; you can also download the zip file and just work from the README I've included.

Related posts:

  1. open_basedir restriction in effect error on WordPress page This is the second time I've run into this problem....
  2. Delink Pages Plugin (Plugin and this post last updated: 10/20/2009 – Latest Plugin...

Related posts brought to you by Yet Another Related Posts Plugin.

3 Responses to "Friendly error pages using PHP and .htaccess"

1 | Lee Stewart

December 16th, 2002 at 6:25 am

Avatar

I wasted all that time making error pages and could have used these?

Although, I have my website eMailing me with the errors, so I think I'm a bigger geek than you guys…

2 | Amy

December 9th, 2002 at 10:21 am

Avatar

Hmmmmm. Yes. I can tell you how to do it in my language of choice (PHP) (everybody quit laughing already!) . It's an UGLY solution, but sometimes ugly problems require…well, you know.

You can repeat the elseif{} section as many times as necessary depending on how many sites you have.

I think $_SERVER['REDIRECT_URL'] is the right PHP variable to use, but I'm bashing this out in a hurry. Expect syntax errors and the like, but I think this is at least a start for a solution.

Anyway, here 'tis.

<?
if(stristr($_SERVER['REDIRECT_URL'],"main_name_of_first_site")) { ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>404 – File not found.</title>
</head>
<body>
<h1>404. File not found.</h1>
<p>That file (<strong>http://example.com<?= $_SERVER['REQUEST_URI'] ?></strong>) does not exist. Other nicely apologetic language can go here.</p>
</body>
</html>
<? }
elseif(stristr($_SERVER['REDIRECT_URL'],"main_name_of_second_site")) { ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>404 – File not found.</title>
</head>
<body>
<h1>404. File not found.</h1>
<p>That file (<strong>http://example2.com<?= $_SERVER['REQUEST_URI'] ?></strong>) does not exist. Other nicely apologetic language can go here.</p>
</body>
</html>
<? }

else { ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>404 – File not found.</title>
</head>
<body>
<h1>404. File not found.</h1>
<p>That file (<strong>http://example3.com<?= $_SERVER['REQUEST_URI'] ?></strong>) does not exist. Other nicely apologetic language can go here.</p>
</body>
</html>
<? } ?>

3 | Scott

December 9th, 2002 at 12:01 am

Avatar

this seams like the right place to ask this: on my host they only let me have one custom 404 (and so on) page, but i am hosting 3 sites, all with totally different looks, i would like to make some php that gets the refering url and check the domain name (cause they all have a different one) and displays certain code, but no clue how to do it, any ideas?

Featured Sponsors


  • Dave Grant Urban: I noticed the same thing; no display in FF if swfobject is in the body. Unfortunately, I can't get to the head section because I use GoDaddy's Quick S
  • C. Scott Asbach: Actually, I had accidentally looked at Chrome instead of Firefox when I thought that worked...(I develop with at least 3 browsers open all th time)
  • C. Scott Asbach: The solution that worked for me was: a:link img{text-decoration:none} Put that after your other a:link,a:visited,a:hover rules and it should wor

About


Advertisements