Jump to content
TNG Community
Sign in to follow this  
Rush

A more friendly 404 page

Recommended Posts

Rush

Nothing to fancy, but I kind of like a little more 'pleasant' 404 page when an visitor clicks on a link that's outdated or wrong.

If they click on an outdated link for Google and get a standard 404 error message, they will probably just run away ;)

This is for the getperson.php file and might come in handy if you renumbered your ID's (like I just did).

At about line 39 in the getperson.php file you should see:

header( "Location: thispagedoesnotexist.html" );

Replace with this:

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://yourwebsite.com/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

It will still produce a valid 404 error, so search engines know to eventually drop the page and helps those visitors to your site.

This would also work with any other file that calls the "thispagedoesnotexist.html" file, like showmedia.php and stuff.

You can check it out here

Rush

Share this post


Link to post
Share on other sites
theKiwi

Replace with this:

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://yourwebsite.com/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

It will still produce a valid 404 error, so search engines know to eventually drop the page and helps those visitors to your site.

This would also work with any other file that calls the "thispagedoesnotexist.html" file, like showmedia.php and stuff.

You can check it out here

This seems like a helpful idea, but alas on your site with the link above I got a completely blank page with no source code.

To fix this remove the last line from your list of lines above, otherwise the page ends up with two instances of

exit;

Roger

Share this post


Link to post
Share on other sites
Rush

Hmmm, not sure why you're not coming up with any source code, seems to be working fine on my end.

I have only one exit; in the modified code

if( !mysql_num_rows($result) ) {

mysql_free_result($result);

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://www.bythedrop.com/e107_plugins/tngIL/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

}

and didn't see a call to exit in my original getperson.php file. :wink:

Rush

Share this post


Link to post
Share on other sites
Ken Roy

Hmmm, not sure why you're not coming up with any source code, seems to be working fine on my end.

I have only one exit; in the modified code

if( !mysql_num_rows($result) ) {

mysql_free_result($result);

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://www.bythedrop.com/e107_plugins/tngIL/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

}

and didn't see a call to exit in my original getperson.php file. :wink:

Rush

Hi Rush,

If you want to make this mod support multi-language, then Line 39 would become (the exit statement is in line 40 in the original code)

    header("HTTP/1.0 404 Not Found");
    echo "<center>";
    echo "<font size=\"5\" face=\"Verdana\"> <b>$text[sorry]</b>";
    echo "<font size=\"3\" face=\"Verdana\">";
    echo "<br /><br />$text[pagemoved]<br />";
    echo "<br />$text[pleaseuse] <a href=$tngdomain/searchform.php>$text[search]</a> $text[tolocate]";
    echo "</font>";
    echo "</center>";
You would then need to add the following entries to your English cust_text.php file
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Sorry!";
$text[pagemoved] = "The page for the person you were looking for may have moved,";
$text[pleaseuse] = "Please use the ";
$text[tolocate] = " feature to locate them.";
and the equivalent to your French cust_text.php (I will accept corrections from my French speaking collegues)
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Désolé!";
$text[pagemoved] = "La page pour la personne que vous recherchiez pourrait avoir été déplacée,";
$text[pleaseuse] = "Veuillez employer la forme de  ";
$text[tolocate] = " pour les localiser.";

You can see the results on my site by setting the language to French or English and then using the folloring URL http://www.royandboucher.com/genealogy/get...&tree=T0001

(Updated URL to my public web site).

The question I have is what modification did you make to get the 404 message page have the look and feel of your site?

Share this post


Link to post
Share on other sites
theKiwi

Hmmm, not sure why you're not coming up with any source code, seems to be working fine on my end.

I have only one exit; in the modified code

if( !mysql_num_rows($result) ) {

mysql_free_result($result);

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://www.bythedrop.com/e107_plugins/tngIL/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

}

and didn't see a call to exit in my original getperson.php file.

in the getperson.php for TNG 6.0.4 there is an exit on line 40 already.

I just tried your site again with Safari and Firefox and get a blank page using this URL

http://www.bythedrop.com/e107_plugins/tngI...mp;tree=Krieger

Ken your link is to your localhost, not to royandboucher.com.

Roger

Share this post


Link to post
Share on other sites
Rush

Nice job Ken Roy...

I'm not sure why my original getperson.php is missing the exit (file still has the original mod date...oh well not to important), but Roger and you are definitely correct that there should only be one 'exit;' :wink:

Maintaining the original feel for the site was easy for me since I'm using a CMS.

The CMS files are called before the TNG file, it renders the menus before the 404 and exit.

I suppose it wouldn't be to hard to modify the modification to call the TNG menu and what not for those folks wanting to keep the same layout.

Just curious if anyone else could chime in if they can see the 'Sorry' message on my site here.

Something might not be correct in an unrelated TNG file, but just want to make sure.

Thanks,

Rush

Share this post


Link to post
Share on other sites
Ken Roy

Maintaining the original feel for the site was easy for me since I'm using a CMS.

The CMS files are called before the TNG file, it renders the menus before the 404 and exit.

Just curious if anyone else could chime in if they can see the 'Sorry' message on my site here.

Thanks,

Rush

Your Sorry page displays fine in Mozilla Suite 1.7.5.

BTW, I changed your line to use the $tngdomain variable. When you look at the URL address it shows two slashes in the URL for the search form but seems to display it correctly.

Share this post


Link to post
Share on other sites
theKiwi

Just curious if anyone else could chime in if they can see the 'Sorry' message on my site here.

Something might not be correct in an unrelated TNG file, but just want to make sure.

Well I'm completely stumped...

I only get a blank page in these situations

Computer A using Mac OS X 10.4.8

Safari

Camino

Netscape

Mozilla

Firefox

Computer A using Windows 98 running under Virtual PC

Firefox

Computer B - a Dull laptop running Windows XP

Firefox

Furthermore, I also get a blank page when trying just the root URL http://bythedrop.com/

So on computer A, log into my AOL account and I can view the page.

The only thing that is in common here is that when I access using my IP number I get the blank page.

When I access with the AOL browser I'm actually using an AOL assigned IP number so it is not my own IP number.

So the question become to Rush is there anything in place with regards to your domain that might be somehow blocking my IP number from your site?

66.93.200.62.

Roger

Share this post


Link to post
Share on other sites
Rush

That's what was wrong...

Sometimes from AOL accounts, it will trip the flood protection on the site.

It should work now ;)

Rush

Share this post


Link to post
Share on other sites
theKiwi

That's what was wrong...

Sometimes from AOL accounts, it will trip the flood protection on the site.

It should work now ;)

Yep I can get in now - my regular IP number is nothing to do with AOL though - it comes from speakeasy.net.

Yes, I see the Sorry message now.

Roger

Share this post


Link to post
Share on other sites
Rush

Ahhh...

Some AOL accounts access the site through various proxies and it was causing the above mentioned problems with the flood control.

You may have accessed the site at one time a while back when I had the configuration too restrictive.

Anyways, sorry about that - didn't mean to drive ya nuts.

Rush

Share this post


Link to post
Share on other sites
Russellgs

Nothing to fancy, but I kind of like a little more 'pleasant' 404 page when an visitor clicks on a link that's outdated or wrong.

If they click on an outdated link for Google and get a standard 404 error message, they will probably just run away ;)

This is for the getperson.php file and might come in handy if you renumbered your ID's (like I just did).

At about line 39 in the getperson.php file you should see:

header( "Location: thispagedoesnotexist.html" );

Replace with this:

header("HTTP/1.0 404 Not Found");

echo "<center>";

echo "<font size=\"5\" face=\"Verdana\"> <b>Sorry!</b>";

echo "<font size=\"3\" face=\"Verdana\">";

echo "<br /><br />The page for the person you were looking for may have moved,<br />";

echo "<br />Please use the <a href=\"http://yourwebsite.com/searchform.php\">SEARCH</a> feature to locate them.";

echo "</font>";

echo "</center>";

exit;

It will still produce a valid 404 error, so search engines know to eventually drop the page and helps those visitors to your site.

This would also work with any other file that calls the "thispagedoesnotexist.html" file, like showmedia.php and stuff.

You can check it out here

Rush

Rush,

I was looking at my getperson.php file and I see two instances of the "thispagedoesnotexist.html" reference the first occurs at line 4 with the following:

if(!$personID) {header( "Location: thispagedoesnotexist.html" ); exit;}

and on line 39. Will this throw off the logic?

If I already created a 404.php page as seen here, do I need this or will it call the page I created?

Russ

Share this post


Link to post
Share on other sites
Rush

Russ,

For the code at line 4:

if(!$personID) {header( "Location: thispagedoesnotexist.html" ); exit;}

If the personID value is empty (e.g.: getperson.php?personID=&tree=FamilyTree) in the URL, it will send it right over to thispagedoesnotexist.html. So the edits on line 39 and below won't mess with any logic. I didn't mess with that line 4 because I wasn't to concerned about links with empty personID values. Though, it's possible modify line 4 in the same fashion.

Going to a custom 404 page might be a little hard. It's good for the visitor, but bad for search engines. Since the http header is 302 (Redirect) instead of an actual 404 (Not Found). To get an actual 404 error when going to a custom 404 page, you would need to do a little htaccess file modification.

Rush

Share this post


Link to post
Share on other sites
Ken Roy

Hi Rush,

If you want to make this mod support multi-language, then Line 39 would become (the exit statement is in line 40 in the original code)

    header("HTTP/1.0 404 Not Found");
    echo "<center>";
    echo "<font size=\"5\" face=\"Verdana\"> <b>$text[sorry]</b>";
    echo "<font size=\"3\" face=\"Verdana\">";
    echo "<br /><br />$text[pagemoved]<br />";
    echo "<br />$text[pleaseuse] <a href=$tngdomain/searchform.php>$text[search]</a> $text[tolocate]";
    echo "</font>";
    echo "</center>";
You would then need to add the following entries to your English cust_text.php file
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Sorry!";
$text[pagemoved] = "The page for the person you were looking for may have moved,";
$text[pleaseuse] = "Please use the ";
$text[tolocate] = " feature to locate them.";
and the equivalent to your French cust_text.php (I will accept corrections from my French speaking collegues)
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Désolé!";
$text[pagemoved] = "La page pour la personne que vous recherchiez pourrait avoir été déplacée,";
$text[pleaseuse] = "Veuillez employer la forme de  ";
$text[tolocate] = " pour les localiser.";
You can see the results on my site by setting the language to French or English and then using the folloring URL http://www.royandboucher.com/genealogy/get...&tree=T0001 (Updated URL to my public web site). The question I have is what modification did you make to get the 404 message page have the look and feel of your site?
The following are the changes to make this mod work in TNG 7.0 Replace line 46 in getperson.php
header( "Location: thispagedoesnotexist.html" );
with the following code
//    header( "Location: thispagedoesnotexist.html" ); replaced with custom 404 page Rush/Ken Roy
    header("HTTP/1.0 404 Not Found");
    echo "<center>";
    echo "<font size=\"5\" face=\"Verdana\"> <b>$text[sorry]</b>";
    echo "<font size=\"3\" face=\"Verdana\">";
    echo "<br /><br />$text[personpagemoved]<br />";
    echo "<br />$text[pleaseuse] <a href=$tngdomain/searchform.php>$text[search]</a> $text[tolocateperson]";
    echo "</font>";
    echo "</center>"; // see TNG Forum Entry http://www.tngforum.us/index.php?s=&showtopic=2186&view=findpost&p=9701 Rush/Ken Roy
Note that the $text changes are slightly different since I reworked the mod to also support a similiar mod to showsource.php Changes to English/cust_text.php
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Sorry!";
$text[personpagemoved] = "The page for the person you were looking for may have moved,";
$text[pleaseuse] = "Please use the ";
$text[tolocateperson] = " feature to locate the person.";
Changes to French/cust_text.php
// Added for Person Not Found message in getperson.php 404 error message
$text[sorry] = "Désolé!";
$text[personpagemoved] = "La page pour la personne que vous cherchez peut-être déplacée,";
$text[pleaseuse] = "Veuillez employer la forme de ";
$text[tolocateperson] = " pour localiser la personne.";

See also TNG Wiki Message 404 - getperson Mod

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×