13, February 2012

[Modification] Don't waste your 404s - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web site promotion  >  Promoting & building a forum  >  SMF moding & promoting
Topic: [Modification] Don't waste your 404s
« previous next »
Pages: [1] 2 Print
Instabuck - The easy way to sell digital products online

Author Topic: [Modification] Don't waste your 404s  (Read 5655 times)
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« on: Aug 16, 2006, 05:30:22 pm »

This is a small tutorial that will help your smf forum use better the 404 errors.

Actually it can easilly addapted to any kind of site with some small modifications.

The purpose of this script is to redirect any 404 to a search page, like the php.net site.

For example if someone hits http://www.webdigity.com/adsense , it will be redirected to the search page with search cretiria seted to "adsense".

Here is what you have to do :

1) Open your .htaccess file.

2) Add this line :

Code:
ErrorDocument 404 /err.php

Then open your favorite text editor (eg. notepad) and copy the above code :

Code:
<?php
header
("HTTP/1.0 200");
?>

<body onload=frm1.submit();>
<table width=100% height=100%>
<tr><td align=center valign=middle>
<font style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:14px;">
The page you requested does not exist. <br />You will be automatically redirected to the search page
</font>
</td></tr></table>
<form method=post action="/index.php?action=search2" name=frm1>
<input type=hidden name=search value="<?echo urldecode(substr($_SERVER["REQUEST_URI"],1));?>">
</form>
</body>
<?php
 $fp 
fopen("404.txt""a");
 
fwrite($fpsubstr($_SERVER["REQUEST_URI"],1) . "\n" );
 
fclose($fp);
?>


Now you are ready, save the file named err.php and upload it to your forum's site. You are done Wink
« Last Edit: Sep 12, 2006, 11:06:49 am by Nikolas »

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



Re: Don't waste your 404s
« Reply #1 on: Aug 16, 2006, 05:34:50 pm »

Forgot to tell.

The last 3 lines of code are not nessecery and maybe the modification wont work with them in some hosts.

Code:
<?php
 $fp 
fopen("404.txt""a");
 
fwrite($fp$_SERVER["REQUEST_URI"] . "\n" );
 
fclose($fp);
?>


The purpose of these lines is to log the unresolved pages to a file named 404.txt

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Aug 16, 2006, 10:59:26 pm »

I use some similat code and also report the errors to my mail (if a referer exists)

Code:
<?php
$docroot 
"http://".$_SERVER['HTTP_HOST'];
if (isset(
$_GET['err'])) { 
$errorNum $_GET['err'];
} else {
$errorNum "undef. number";
}

$emailaddress "mail@website.com";
$filename $docroot."/blocked_ref.txt";
if (!empty(
$_SERVER['HTTP_REFERER'])) {
$bad_ref file ($filename);
$bad_counter 0;
foreach ($bad_ref as $val) {
if (substr($_SERVER['HTTP_REFERER'], 020) == substr($val020)) {
$bad_counter++;
}
}
if ($bad_counter 0) {
header("Location: http://www.website.com");
die();
} else {
$errortime = (date("d M Y h:m:s")); 
$message $errorNum." Error Report\r\n\r\nA ".$errorNum." error was encountered by ".$_SERVER['REMOTE_ADDR'];
$message .= " on $errortime.\r\n\r\n";
$message .= "The URI which generated the error is: \n".$docroot.$_SERVER['REQUEST_URI']."\r\n\r\n";
$message .= "The referring page was:\n".$_SERVER['HTTP_REFERER']."\r\n\r\n";
$message .= "The used client was:\n".$_SERVER['HTTP_USER_AGENT']."\r\n\r\n";
$headers "From: ".$emailaddress."\nDate: ".$errortime." +0100\n";
$subject "Error: ".$errorNum." from ".$_SERVER['HTTP_REFERER'];
mail($emailaddress$subject$message$headers);
}
} else {
$bad_ref file ($filename);
$very_bad_counter 0;
foreach ($bad_ref as $val) {
if (substr($_SERVER['REMOTE_ADDR'], 010) == substr($val010)) {
$very_bad_counter++;
}
}
if ($very_bad_counter 0) {
header("Location: http://www.google.nl");
die();
}
}


this script has some extra functions to redirect requests (hotlinking) and also "known problems"


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #3 on: Aug 17, 2006, 09:37:52 am »

I think you could do this much faster by keeping only the domains of the bad referers in the file, and then search with the in_array function.

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Aug 17, 2006, 09:45:20 am »

I think you could do this much faster by keeping only the domains of the bad referers in the file, and then search with the in_array function.

This what I do, just some example:

62.253.64.19
http://forum.donanimhaber.com/m_1461509/mpage_1/key_php%252Cwhois%252Cscript//tm.htm#1461509

the IP address is a "bad one" and the url is about a page with a bad link


Last blog : A new Wordpress theme for our blog
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Aug 17, 2006, 09:46:32 am »

... This way the script is showing me (external and internal) broken links


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #6 on: Aug 17, 2006, 09:49:03 am »

You could keep only the domain of the bad referer (eg. forum.donanmhaber.com ) and then do this :

Code:
<?php
$badHosts 
file 'badhosts.txt' );
$ref parse_url$_SERVER['HTTP_REFERER'] );
if ( 
in_array$ref['host'] . "\n" $badHosts ))// The \n is because file() leaves a \n character after each record.
{
  
//Catch ya :)
}

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Aug 17, 2006, 09:53:21 am »

yes you're right if there are more the one pages on a website with bad links, most of the time its only one, that I look for a longer URL is for me to know if this is the only link...


But maybe this is a nice script for the code gallery...


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #8 on: Aug 17, 2006, 10:22:01 am »

Quote
But maybe this is a nice script for the code gallery...

Yeah good idea. Will you add it or should I?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Aug 17, 2006, 10:44:11 am »

Quote
But maybe this is a nice script for the code gallery...

Yeah good idea. Will you add it or should I?
I will...


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #10 on: Aug 17, 2006, 10:47:36 am »

Ok, thanks Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Aug 17, 2006, 11:54:25 pm »

Hello,

here is the tutorial:
http://www.webdigity.com/index.php?action=tutorial;code=30

Nick, maybe you want to add some additional SMF code


Last blog : A new Wordpress theme for our blog
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #12 on: Aug 18, 2006, 11:07:39 am »

Thanks. I will propably add this as an additional tutorial and cross link both of them

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I love Pokemon
*
Posts: 14
92 credits
Members referred : 0


« Reply #13 on: Sep 10, 2006, 08:01:15 pm »

This looks good but the search term includes a / such that the term "adsense" becomes "/adsense" limiting the search results. You can see that in the example link above http://www.webdigity.com/adsense. The search result is "/adsense" and not just "adsense". I hope the / can be removed from the search term.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #14 on: Sep 10, 2006, 08:59:11 pm »

Thanks for the heads up geezmo, and BTW welcome to our community Wink

The SMF snippet has been corrected now(check the first post).

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I love Pokemon
*
Posts: 14
92 credits
Members referred : 0


« Reply #15 on: Sep 14, 2006, 08:27:53 pm »

My site is at www.mysite.com/forum and when I used the code in the first post, it doesn't redirect to the forum's search page but rather it goes to the main index page. How to solve this?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #16 on: Sep 14, 2006, 08:29:52 pm »

My site is at www.mysite.com/forum and when I used the code in the first post, it doesn't redirect to the forum's search page but rather it goes to the main index page. How to solve this?

change this line :

<form method=post action="/index.php?action=search2" name=frm1>

to this :

<form method=post action="/forum/index.php?action=search2" name=frm1>

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I love Pokemon
*
Posts: 14
92 credits
Members referred : 0


« Reply #17 on: Sep 14, 2006, 08:43:34 pm »

I tried that but what happened was it didn't load.. I got a /forum/forum/forum/forum/forum/index.php... error..

Also, I checked Google Sitemaps and it said it can't verify my site because the 404 error is now being recognized as a 202 page. This caused problem to my Google Sitemaps so I just chose to uninstall this. Now Sitemaps is doing ok again.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5778
46265 credits
Members referred : 3



« Reply #18 on: Sep 15, 2006, 07:41:10 pm »

To avoid the sitemaps problem (which actually is not a real problem) you can remove this line from the script :
header("HTTP/1.0 200");

Now regarding the error you get, can you give some more feedback? Is it a php error or something else? Did you put all the files that mentioned in your forum/ directory?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Metal slug addict
*
Posts: 18
108 credits
Members referred : 0


« Reply #19 on: Dec 01, 2006, 09:56:53 am »

Thanks. I will propably add this as an additional tutorial and cross link both of them
Are u finished with this? Smiley

And other problems that appear is that when page is redirect to the search page, there isnt search results for  the word which cause that error and i'm sure that word is posted on the forum for milion times.   
« Last Edit: Dec 01, 2006, 10:12:31 am by Pharmacy »
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=3700
Tags : php google tutorials domains snippets Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web site promotion  >  Promoting & building a forum  >  SMF moding & promoting
Topic: [Modification] Don't waste your 404s
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Feb 13, 2012, 04:20:20 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.