scriptygoddess RSS Feed
 
 
 
 

Friendly error pages using PHP and .htaccess

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. 1
    Scott:

    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. 2
    Amy:

    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. 3
    Lee Stewart:

    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…

Bookmarks

WordPress Resources

Meta