sNews Forum

Previous sNews versions => sNews 1.5 RC and pre-release => sNews 1.5 RC3 version => Topic started by: Mika on November 28, 2006, 06:12:29 pm

Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Mika on November 28, 2006, 06:12:29 pm
This mod is still in development stage*
applies to: sNews 1.5 RC1-3
version: 0.8

1. backup your .htaccess and snews.php files

2. create file called 404.htm and upload it to your sNews installation folder (the site root or in a folder where your sNews installation resides)

3. .htaccess file
- insert your domain name (and folder if needed)
Quote
# add this line somewhere at the top of .htaccess file
ErrorDocument 404 http://your-domain/404.htm
# if using subfolder then use the next line instead
ErrorDocument 404 http://your-domain/your-snews-folder/404.htm
4. snews.php - replace entire function or just paste changes to the code from BEGIN to END
Quote
// STARTUP
function snews_startup() {
   connect_to_db();
   if (get_id('category') == 'rss') {rss(); die;}
   update_articles();
   if (isset($_POST['Loginform']) == 'True') {
      if (clean($_POST['uname']) == s('username') && md5(clean($_POST['pass'])) == s('password')) {
         $_SESSION[db('website').'Logged_In'] = 'True'; $_SESSION['uname'] = s('username'); $_SESSION['Website'] = db('website');
      }
   }
/*NEW CODE BEGIN*/
   $categorySEF = get_id('category'); $articleSEF = get_id('article');
   $cat = retrieve('seftitle', 'categories', 'seftitle', $categorySEF);
   $art = retrieve('seftitle', 'articles', 'seftitle', $articleSEF);
   if ((!empty($categorySEF) && $cat == false && check_category($categorySEF) != true) || (!empty($articleSEF) && $art == false)) {
      echo '';
   }
/*NEW CODE END*/
}
snews_startup();
If you want to see this mod in action, feel free to rape my site (http://www.ni5ni6.com/) :D
_____________
* This is one of my quick fixes - I still need to fix appropriate response headers, and some minor details...
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: iatbm on November 28, 2006, 06:50:06 pm
Yea it kind of works Mika but still the server put out 200 OK status and not 404 :(
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Mika on November 28, 2006, 07:00:42 pm
yep, I've already said that headers need fixing ;)
unless you come up with the fix, I'll deal with it when time permits me, okay?
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: iatbm on November 28, 2006, 07:09:20 pm
all right hehe ;) I missed that *
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Patric Ahlqvist on November 28, 2006, 07:30:56 pm
GOD AL FECKING MIGHTY: http://www.ni5ni6.com/four-o-four.htm :lol:
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Mika on November 29, 2006, 06:31:50 am
hehe...remember that?
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: bramsyuur on November 29, 2006, 06:40:59 am
Thanks Mika for another contribution!  ;)
Try to adding this :
Quote
header("HTTP/1.1 404 Not Found");
before this line:
Quote
echo '';
I've revised my apache log's and I see the correct header "404 Error" line:
Quote
127.0.0.1 - - [29/Nov/2006:14:31:16 +0900] "GET /blablabla HTTP/1.1" 404 9672
In some cases, the header("HTTP/1.1 404 Not Found"); don't work as expected (because of type of php compilation in the server). In this case, use this alternative:
Quote
header("Status: 404 Not Found");
Thanks,
bram.
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: markuz on December 02, 2006, 10:54:12 am
This is a good add-on and increases usability and decreases user's confusion in case of an error. That's why it definitely should be a core function. It is recommended, that the error pages should be always customized with all the needed information (see e.g. Jacob Nielsen), but I always want to remind people, that the user must feel, that they have the control over what they do, and one think to make that possible is consistency. By making a separate error page which doesn't follow the sites design confuses the user.

So my wish is to have an error page with a correct header within the site. By implementing that, the error page would also became editable through the admin settings, wouldn't it?
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: markuz on December 02, 2006, 12:48:50 pm
By the way, there is a slight problem with non-english sites. If you change the Home SEF from the settings to something else than 'home' you get error page when trying to access pages, which have that word in url. One solution is to add that Home SEF into the $l['cat_listSEF']-array afterwards, but it would be better, if there would be an automatic solution.
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Vorsoron on December 03, 2006, 12:27:47 pm
I found another problem... When I click Next on Pagination, it recognizes as a 404 and redirects to the 404 page.
Title: [MOD / ADDON] sNews 404 error page (sNews 1.5 RC1-3)
Post by: Mika on December 03, 2006, 12:38:45 pm
If you're using 1.5 stable, then you don't need this mod. However, if you do want to create custom 404, then use only htaccess part of the mod.