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.

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

1 | 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?

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&lt;?= $_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&lt;?= $_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&lt;?= $_SERVER['REQUEST_URI'] ?></strong>) does not exist. Other nicely apologetic language can go here.</p>
</body>
</html>
<? } ?>

3 | 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…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements