Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Mika...help...404 ?  (Read 8272 times)

iatbm

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 251
    • Public domain photos
Mika...help...404 ?
« on: March 28, 2007, 10:08:59 AM »

I was browsing through topics for 404 error page and saw that you said that in .31 if I am not mistaken we don't need 404 addon you made. I still get 200 headers when there is no page available.

Can you please take a little of your time and post what to do ? :)

I would highly appreciate ...
« Last Edit: July 23, 2009, 07:09:01 PM by philmoz »
Logged

Elvino

  • Newbie
  • *
  • Karma: 0
  • Posts: 44
    • http://www.elvino.it/
Mika...help...404 ?
« Reply #1 on: April 03, 2007, 07:35:20 PM »

the error page with header 404 it's a very important for SEO ...

   
wait for mika   ;)
« Last Edit: July 23, 2009, 07:09:33 PM by philmoz »
Logged

iatbm

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 251
    • Public domain photos
Mika...help...404 ?
« Reply #2 on: April 08, 2007, 11:53:22 AM »

Quote from: Elvino
the error page with header 404 it's a very important for SEO ...
   
wait for mika   ;)
Yes I am waiting ;)

I wish he or Luka would do something about it :)
« Last Edit: July 23, 2009, 07:10:20 PM by philmoz »
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
Mika...help...404 ?
« Reply #3 on: April 09, 2007, 10:13:47 AM »

Sorry if I've kept you waiting too long lads - one of drawbacks of being promoted is increased rate of business trips :|

This is what you could do to obtain proper response header for 404 error page (all the editing is done inside snews.php)

1. add 2 new lines at the bottom of the function snews_startup()
Quote
...
}
}
#new code - begin
$category = get_id('category');
if ($category == '404') {header404();}

#new code - end
}
snews_startup();
2. add new function header404() below snews_startup()
Quote
function header404() {
# some PHP versions have a 404 header bug and the commented line is the workaround
# test it and use the one which sends the correct 404 header on your server
//header('Status: 404 Not Found');
header('HTTP/1.1 404 Not Found');
}
3. edit center() function as follows:
Quote
...
# create a new switch statement
switch ($action) {
...
case 'archive': archive(); break;
case '404': echo 'your error message here'; break;
# note: edit error message as you see fit
...
# find the red code several lines below and replace it with the blue one
...
if (!$result_articles) {echo '<h2>'.l('not_found').'</h2>'; break;}
if (!$result_articles) {echo '<meta http-equiv="refresh" content="0; url='.db('website').'404/">'; break;}
...
if (!$result || !$numrows) {echo '<h2>'.l('not_found').'</h2>';}
if (!$result || !$numrows) {echo '<meta http-equiv="refresh" content="0; url='.db('website').'404/">';}
« Last Edit: July 23, 2009, 07:33:40 PM by philmoz »
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

iatbm

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 251
    • Public domain photos
Mika...help...404 ?
« Reply #4 on: April 09, 2007, 12:57:59 PM »

super duper thanks Mika  :D

Going to do this later today....

Hey trips are always good hehe

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
Mika...help...404 ?
« Reply #5 on: April 09, 2007, 09:13:11 PM »

Quote
Hey trips are always good hehe
Oh, I couldn't agree more - but only when they're not business related ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Elvino

  • Newbie
  • *
  • Karma: 0
  • Posts: 44
    • http://www.elvino.it/
Mika...help...404 ?
« Reply #6 on: April 10, 2007, 08:44:35 PM »

Thank you Mika!

my small mod:

change
case '404': echo 'your error message here'; break;

with:
case '404': echo l('error_404'); break;

and add on language:
$l['error_404'] = '<h2>Error 404</h2><p>Bla bla bla...</p>';
« Last Edit: July 23, 2009, 06:59:01 PM by philmoz »
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Mika...help...404 ?
« Reply #7 on: April 11, 2007, 06:28:35 AM »

very nice Mika and Elvino ;)
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

4dd1ct

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
Mika...help...404 ?
« Reply #8 on: April 11, 2007, 12:13:15 PM »

This won't work since it relies on a meta refresh to a non existent category:

Code: [Select]
<meta http-equiv="refresh" content="0; url='.db('website').'404/">
So the request for a missing category or article will still return a 200 response. I'll see if I can figure out a workaround.
« Last Edit: July 23, 2009, 07:32:05 PM by philmoz »
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Mika...help...404 ?
« Reply #9 on: April 25, 2007, 08:24:11 AM »

Aren't that code in center() completely useless as headers (I believe 200) has already been sent to browser?
Logged

4dd1ct

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
Mika...help...404 ?
« Reply #10 on: April 25, 2007, 11:36:41 PM »

Quote from: codetwist
Aren't that code in center() completely useless as headers (I believe 200) has already been sent to browser?
In a word, yes.

I haven't figured out an alternative that will make it very easy to upgrade snews though, unfortunately or I would offer it here...
Logged

4dd1ct

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
Mika...help...404 ?
« Reply #11 on: April 26, 2007, 12:32:36 AM »

Thatnks ognennyjstorm, this is getting close. A few comments:

The modifications to the center()  function are unnecessary - since this function outputs to the browser it is not possible to set HTTP headers here.

The modification only works for categories that don't exist, not articles, so domain/snews/MISSING/article will work work, but domain/category/MISSING will not.

I would also remove the call for the script to exit (die). The sNews message is fine for visitors, it just returns a misleading HTTP status code.
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
Mika...help...404 ?
« Reply #12 on: April 27, 2007, 08:53:49 PM »

Tell me what do you think of this:
Add new lang variable
Quote
$l['error_404'] = 'Requested contents cannot be found. Please go back or use the search feature.';
Add the blue code to the snews_startup() function (code updated on 29.4.07)
Quote
function snews_startup() {
   connect_to_db();
   $categorySEF = get_id('category');
   $articleSEF = get_id('article');

   if ($categorySEF == 'rss') {rss(); die;}
   $home = s('home_sef');
   $homeSEF = empty($home) ? l('home_sef') : $home;
   $categoryID = $categorySEF == $homeSEF ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
   $articleCatID = retrieve('category', 'articles', 'seftitle', $articleSEF);
   if (!empty($categorySEF) && $categorySEF != '404') {
      switch(true) {
         case (!$categoryID && check_category($categorySEF) == false):
         case (!empty($articleSEF) && false === strpos($articleSEF,l('paginator')) && $articleCatID != $categoryID):
         header('Location: '.db('website').'404/'); exit;
       break;
      }
   }
   if ($categorySEF == '404') {
      /*
       some PHP versions have a 404 header bug and the commented line is the workaround
       test it and use the one which sends the correct 404 header from your server
       */
       //header('Status: 404 Not Found');
      header('HTTP/1.1 404 Not Found');
   }

   update_articles();
...
...
Add new function after snews_startup()
Quote
// 404 ERROR PAGE
function error404() {
   echo l('error_404');
}
Add the blue code to the center() function
Quote
function center() {
...
...
switch ($action) {
   case 'archive': archive(); break;
   case 'sitemap': sitemap(); break;
   case 'contact': contact(); break;
   case 'login': login(); break;
   case '404': error404(); break;
   default:
...
...
AFAIK, this tweak should resolve duplicated contents issue as well.
« Last Edit: July 23, 2009, 07:01:04 PM by philmoz »
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Mika...help...404 ?
« Reply #13 on: April 27, 2007, 09:39:08 PM »

To resolve 'duplicated content' issue for existing articles comparison of 'category' value from articles record with $categoryName would be handy.
« Last Edit: July 23, 2009, 07:12:21 PM by philmoz »
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Mika...help...404 ?
« Reply #14 on: April 28, 2007, 08:58:17 AM »

I like the direction this thread is heading.. keep the ideas flowing :)
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future
Pages: [1] 2