Jump to content
Jack_mcs

Custom Server Error Pages

Recommended Posts

This isn't my contribution. I was asked to install it for someone and found the code would not work as it was. I also couldn't find a support thread for it so this will serve as it unless the original author wants to start one.

 

Every site should have a customer 404 page (as well as others). If you don't have one, the default one will be used and all that says is the page can't be found. Plus, the browser will attempt to load a default 404 page, which eats up the bandwidth. So, all in all, this is one of those little contributions that all shops need.

 

The contribution can be found here.

 

Jack

Edited by Jack_mcs

Share this post


Link to post
Share on other sites

hello jack , always so efficient i see you everywhere

 

i'm tryind to add an email alert report plus the creation of a log file on the server with all dated infos

would you want to beta test ?


MS2

Share this post


Link to post
Share on other sites

Sure, I'll give it a try though I can't say when. Please feel free to send it to me. If you are going to send emails though, you may want to add an option to only send if not a spider or you may get flooded with emails.

 

Jack

Share this post


Link to post
Share on other sites

well by chance i had a friend having a version of "http errors"

that make all that and is not availaible anymore on oscommerce

i will take from this contribution and "custom server error pages" and make the best package

 

as for the spider i got no idea on how to handle them

 

by the way any exemple on how to write the htacess. paths

 

does it has to be at the root of the domain folder o the server

or in the shop catalog folder ?


MS2

Share this post


Link to post
Share on other sites

Jack,

 

I installed the new version of the contribution and it seems to work some of the time.

 

If I type in an incomplete url: http://www.mysite.com/osc/garbage , the custom contribution 404 page appears.

 

If I type in a complete, not found url: http://www.mysite.com/osc/garbage.php the default 404 page appears.

 

Is this the issue that you found when you installed or is there something else that would be causing this?

 

 

Bob

Edited by cactustactical

Share this post


Link to post
Share on other sites
well by chance i had a friend having a version of "http errors"

that make all that and is not availaible anymore on oscommerce

i will take from this contribution and "custom server error pages" and make the best package

 

as for the spider i got no idea on how to handle them

 

by the way any exemple on how to write the htacess. paths

 

does it has to be at the root of the domain folder o the server

or in the shop catalog folder ?

See the code in the includes/application_top.php file for how to check if it is a spider. You just need to use that code (if ($spider_flag == true) { don't send email).

 

The install instructions has an example for the path, although it may not be clear. in the line

ErrorDocument 404 /catalog/server_error.php?id=404

, that first / after the 404 refers to the root of the site. So if the shop is in the root, the path would be /server_error.php. But if you have an entrance page in the root and the shop in the catalog directory. The server_errror.php file would go in the catalog directory and the .htaccess file changes would go in both directories. You can also use a full path if you like but it isn't necessary.

 

Jack

Share this post


Link to post
Share on other sites
Jack,

 

I installed the new version of the contribution and it seems to work some of the time.

 

If I type in an incomplete url: http://www.mysite.com/osc/garbage , the custom contribution 404 page appears.

 

If I type in a complete, not found url: http://www.mysite.com/osc/garbage.php the default 404 page appears.

 

Is this the issue that you found when you installed or is there something else that would be causing this?

 

 

Bob

I tried it here and the error page is displayed when I type in either. The only thing that controls that in this contribution is the .htaccess file changes so I would look there for a mistake.

 

Jack

Share this post


Link to post
Share on other sites

I figured it would be in htaccess since the contribution page appears when entered directly in the command line, but the puzzler is that I copied the hatacess code straight from the contribution and only changed the directory name to match my structure.

 

What would be the mistake below and if something was mistyped, why would it work on an incomplete url and not on a complete url?

 

 

ErrorDocument 400 /osc/server_error.php?id=400

ErrorDocument 401 /osc/server_error.php?id=401

ErrorDocument 402 /osc/server_error.php?id=402

ErrorDocument 403 /osc/server_error.php?id=403

ErrorDocument 404 /osc/server_error.php?id=404

ErrorDocument 405 /osc/server_error.php?id=405

ErrorDocument 406 /osc/server_error.php?id=406

ErrorDocument 407 /osc/server_error.php?id=407

ErrorDocument 408 /osc/server_error.php?id=408

ErrorDocument 409 /osc/server_error.php?id=409

ErrorDocument 410 /osc/server_error.php?id=410

ErrorDocument 411 /osc/server_error.php?id=411

ErrorDocument 412 /osc/server_error.php?id=412

ErrorDocument 413 /osc/server_error.php?id=413

ErrorDocument 414 /osc/server_error.php?id=414

ErrorDocument 415 /osc/server_error.php?id=415

ErrorDocument 416 /osc/server_error.php?id=416

ErrorDocument 417 /osc/server_error.php?id=417

ErrorDocument 421 /osc/server_error.php?id=421

ErrorDocument 422 /osc/server_error.php?id=422

ErrorDocument 423 /osc/server_error.php?id=423

ErrorDocument 424 /osc/server_error.php?id=424

#ErrorDocument 425 /osc/server_error.php?id=425

#ErrorDocument 426 /osc/server_error.php?id=426

#ErrorDocument 449 /osc/server_error.php?id=449

ErrorDocument 500 /osc/server_error.php?id=500

ErrorDocument 501 /osc/server_error.php?id=501

ErrorDocument 502 /osc/server_error.php?id=502

ErrorDocument 503 /osc/server_error.php?id=503

ErrorDocument 504 /osc/server_error.php?id=504

ErrorDocument 505 /osc/server_error.php?id=505

ErrorDocument 506 /osc/server_error.php?id=506

ErrorDocument 507 /osc/server_error.php?id=507

ErrorDocument 508 /osc/server_error.php?id=508

ErrorDocument 509 /osc/server_error.php?id=509

ErrorDocument 510 /osc/server_error.php?id=510

Share this post


Link to post
Share on other sites

The code looks fine. Try placing the errordocument code at the beginning of the .htaccess file as opposed to the end, if it is not there now. If that isn't it, try going to http://www.mysite.com/osc/privacyx.php. If the server_error page is displayed, then the other is failing because of a reserverd list of files your host has. If that doesn't help, then you need to contact your host to find out why the redirection is failing. It must be something they have set that is preventing it.

 

Jack

Share this post


Link to post
Share on other sites

The errordocument code is set at the beginning of htacess and the same result occurs:

 

enter an incomplete url ( http://www.mysite.com/junk )and the contribition error page is displayed

 

enter the complete url ( http://www.mysite.com/junk.php) and the default IE 404 error page displays.

 

 

 

Per your suggestion, entered http://www.mysite.com/shippings.php ( extra s on the end of shipping) and the shipping page is returned properly.

 

But entered 2 extra 's' on the end of shipping.php and the default IE 404 page is displayed.

 

 

Do you use the Ultimate SEO Url's contribution on the site that you have added this contribution to?

 

Wondering if the rewrites for that are causing a problem with the code.

Share this post


Link to post
Share on other sites

I have a problem.

 

If a customer has items in the cart and goes to a 404 error page then the contents of the cart get removed. Is there any way of keeping the cart when page not found?

Share this post


Link to post
Share on other sites
The errordocument code is set at the beginning of htacess and the same result occurs:

 

enter an incomplete url ( http://www.mysite.com/junk )and the contribition error page is displayed

 

enter the complete url ( http://www.mysite.com/junk.php) and the default IE 404 error page displays.

 

Per your suggestion, entered http://www.mysite.com/shippings.php ( extra s on the end of shipping) and the shipping page is returned properly.

 

But entered 2 extra 's' on the end of shipping.php and the default IE 404 page is displayed.

 

 

Do you use the Ultimate SEO Url's contribution on the site that you have added this contribution to?

 

Wondering if the rewrites for that are causing a problem with the code.

I just tried checking the shipping page as yu did - shipping, shippings, shippingss - and all worked as expected and the site I used does have Ultimate SEO installed. Plus, Ultimate SEO doesn't do anything with the shipping page so it wouldn't be the cause of the problem. You can turn it off in admin though to verify that if you wish.

 

Jack

Share this post


Link to post
Share on other sites
I have a problem.

 

If a customer has items in the cart and goes to a 404 error page then the contents of the cart get removed. Is there any way of keeping the cart when page not found?

No, the session ID is being lost and there's no way, at least that I know of, to pass it via the .htaccess file. But the say thing would happen without this contribution so it doesn't make a difference, in that sense.

 

Jack

Share this post


Link to post
Share on other sites

Jack,

 

I was pretty sure that it was related to a version of Ultimate SEO Urls and dipped into what we had installed for that. I did find that FWR Media had included a worthwhile addon to USU which does the following, attempts to prevent Google duplicate content penalties by correcting typos in urls entered to what it thinks should be the correct value.

 

in functions/general.php, adds the following code. I have bolded the relevant section. Basically, if a url can not be corrected ( in my case, entering an incomplete url without the php or html, nothing happens) but, if a full url is entered which can not be corrected, it forces a default 404 page, bypassing what is done in the error document contribution. This is a worthwhile addon as it does correct mis-typings, so I will play around with it a bit and see what I can come up. Will also contact Robert and let him know of this situation.

 

 

################################################

// fwrmedia.co.uk mod to check SEO link validity

function tep_validate_seo_urls() {

global $HTTP_GET_VARS, $request_type;

( $request_type == 'NONSSL' ? $fwr_server_port = HTTP_SERVER : $fwr_server_port = HTTPS_SERVER );

$querystring = str_replace('?', '&', $_SERVER['REQUEST_URI']);

if (isset($HTTP_GET_VARS['products_id']))

$get_id_vars = str_replace(strstr($HTTP_GET_VARS['products_id'], '{'), '', $HTTP_GET_VARS['products_id']); // Remove attributes

$qs_parts = explode('&', $querystring); // explode the querystring into an array

$count = count($qs_parts);

$added_uri = array();

$remove_nasties = array('%3C', '%3E', '<', '>', ':/', 'http', 'HTTP'); // We do tep_sanitize_string() later anyway

for ( $i=0; $i<$count; $i++ ) { // We don't want to introduce vulnerability do we :)

switch($qs_parts[$i]) {

case(false !== strpos($qs_parts[$i], '.html')):

$core = urldecode($qs_parts[$i]); // Found the path

( (strstr($core, '{') !== false) ? ($core = str_replace(strstr($core, '{'), '', $core) . '.html') : NULL ); // Remove attributes

break;

case(false !== strpos($qs_parts[$i], 'osCsid')):

$seo_sid = $qs_parts[$i]; // Found the osCsid

break;

default:

$added_uri[] = ( urldecode(str_replace($remove_nasties, '', $qs_parts[$i])) ); // Found the additional querystring (e.g. &page=3&sort=2a from split_page_results)

}

}

$do_validation = true; // Set to false later if it is not an seo url so that other .html files pass through unhindered

// If -x- is in the querystring create var $querytype which is a string which explodes into an array on -

( strpos($_SERVER['REQUEST_URI'], '-p-') ? ($querytype = 'filename_product_info-products_id=' . $get_id_vars) :

( strpos($_SERVER['REQUEST_URI'], '-c-') ? ($querytype = 'filename_default-cPath=' . $HTTP_GET_VARS['cPath']) :

( strpos($_SERVER['REQUEST_URI'], '-m-') ? ($querytype = 'filename_default-manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']) :

( strpos($_SERVER['REQUEST_URI'], '-pi-') ? ($querytype = 'filename_popup_image-pID=' . $HTTP_GET_VARS['pID']) :

( strpos($_SERVER['REQUEST_URI'], '-t-') ? ($querytype = 'filename_articles-tPath=' . $HTTP_GET_VARS['tPath']) :

( strpos($_SERVER['REQUEST_URI'], '-a-') ? ($querytype = 'filename_article_info-articles_id=' . $HTTP_GET_VARS['articles_id']) :

( strpos($_SERVER['REQUEST_URI'], '-pr-') ? ($querytype = 'filename_product_reviews-products_id=' . $get_id_vars) :

( strpos($_SERVER['REQUEST_URI'], '-pri-') ? ($querytype = 'filename_product_reviews_info-products_id=' . $get_id_vars) :

( strpos($_SERVER['REQUEST_URI'], '-prw-') ? ($querytype = 'filename_product_reviews_write-products_id=' . $get_id_vars) :

( strpos($_SERVER['REQUEST_URI'], '-i-') ? ($querytype = 'filename_information-info_id=' . $HTTP_GET_VARS['info_id']) :

( strpos($_SERVER['REQUEST_URI'], '-links-') ? ($querytype = 'filename_links-lPath=' . $HTTP_GET_VARS['lPath']) :

$do_validation = false )))))))))) );

 

if ( true === $do_validation ) { // It's an SEO URL so we will validate it

$validate_array = explode('-', $querytype); // Gives e.g. $validate_array[0] = filename_default, $validate_array[1] = products_id=xx

$linkreturned = tep_href_link(constant(strtoupper($validate_array[0])), $validate_array[1]); // Get a propper new SEO link

// Rebuild the extra querystring

( (strpos($linkreturned, '?') !== false) ? ($seperator = '&') : ($seperator = '?') ); // Is there an osCsid on $linkreturned?

$count = count($added_uri); // Count the extra querystring items

for ($i=0; $i<$count; $i++)

if ($i == 0) $linkreturned = $linkreturned . $seperator . tep_sanitize_string($added_uri[$i]); //add the first using seperator ? or &

else $linkreturned = $linkreturned . '&' . tep_sanitize_string($added_uri[$i]); // Just add "&" this time

$linkreturnedstripped = str_replace( strstr($linkreturned, '?'), '', $linkreturned); // Strip osCsid to allow a match with $core

$linktest = str_replace($fwr_server_port . DIR_WS_HTTP_CATALOG, '', $linkreturned); // Pair the url down to the querystring

if (strpos($linktest, '-') === 0) { // If the link returned by seo.class.php has no text mysite.com/-c-xxx.html

four_o_four_die(); // Product/category does not exist so die here with a 404

exit;

} else if ( $fwr_server_port . $core != $linkreturnedstripped ) { // Link looks bad so 301

$linkreturned = str_replace('&', '&', $linkreturned); // Just in case those sneaky W3C urls tried to throw in an &

header("HTTP/1.0 301 Moved Permanently"); // redirect to the good version

header("Location: $linkreturned"); // 301 redirect

exit;

}

} // We're not doing validation as the -p-, -c- etc was not found

}

function four_o_four_die() { // 404 then redirect doesn't work as Google records a 302 so we need to die here with a 404

echo

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

'<p align="left" style="font-size: large;">  404 Page not found!</p>

<div align="center" style="width: 100%; margin-top: 70px;">

<div align="center" style="font-family: verdana; font-size: 0.8em; color: #818181; padding: 90px 10px 90px 10px; width: 60%; border: 1px solid #818181;">

This product/category does not exist it may have been deleted.<p />

To return to ' . STORE_NAME .

'. Please click here <a href="' . tep_href_link(FILENAME_DEFAULT) . '" title="' . STORE_NAME . '">back to ' . STORE_NAME . '</a>

</div></div>';}

################################################

// END fwrmedia.co.uk mod to check SEO link validity

Share this post


Link to post
Share on other sites

You would need to check with FWRMedia to be sure but my guess is that all that is needed is to replace the contents of the four_o_four_die function with a redirect to the server_error.php page.

 

Jack

Share this post


Link to post
Share on other sites

Hi Jack, I hope you'll find time to answer this:

 

I have KISS error handler installed which reports:

 

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

Date / Time: 31-01-2011 18:03:42

Error Type: [E_NOTICE] Undefined variable: error_id

On line 422

File includes/languages/svenska/access_error.php

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

Date / Time: 31-01-2011 18:03:42

Error Type: [E_NOTICE] Undefined index:

On line 422

File includes/languages/svenska/access_error.php

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 

I have renamed server_error.php to access_error.php

 

The lines in question are:

 

define('SERVER_ERROR_NUMBER', $server_error_number[$error_id]);

define('SERVER_ERROR_TITLE', $server_error_title[$error_id]);

define('SERVER_ERROR_TEXT', $server_error_text[$error_id]);

 

I wonder if it's got something to do with:

 

<td class="pageHeading" align="center"><?php echo $server_error_title[$error_id]; ?></td> ?

 

I noticed that you have this in v1.1:

<td class="pageHeading"><?php echo $server_error_number[$server_error_id]; ?> <?php echo $server_error_title[$server_error_id]; ?>:</td>

 

Is it enough to change that <td> -tag to yours?

 

Or are ther more bug fixes?

 

Sara

Share this post


Link to post
Share on other sites

The contribution can be found here.

 

Jack

 

Hi Jack,

 

after installing your Header Status Handler, which works great :D , I've followed also your advise, to install the Custom Server Error Pages, however running into problems.

 

Warning
: require(includes/column_left.php) [function.require]: failed to open stream: No such file or directory in
/home/user/public_html/server_error.php
on line
52

 

Warning
: require(includes/column_left.php) [function.require]: failed to open stream: No such file or directory in
/home/user/public_html/server_error.php
on line
52

 

Fatal error
: require() [function.require]: Failed opening required 'includes/column_left.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/user/public_html/server_error.php
on line
52

 

After doing some research in the forum, I found that column_left.php and column_right.php is no longer included in the newer 2.3.x

Do you plan an update of this module ?

Or is there a newer one available ? I was following another link to your home page oscommerce-solution.com but I only receive a Forbidden error by apache server.

 

Therefore I'm a bit lost right now :wacko:

Edited by mk_osc

Share this post


Link to post
Share on other sites

Installed this in a Bootstrap shop. Works like a charm.

Here the server_error.php file that i use.

<?php
/*
  $server_error_id: server_error.php ver1.2 2015-03-24 $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2015 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SERVER_ERROR);

  $error = true;
  $server_error_id='0';

  // Check for error code
  if(isset($_GET['id'])){
    $server_error_id=$_GET['id'];
 
    //Checks to see if error has a valid id, if not then sets to "unknown"
    if (in_array($server_error_id, $server_error_number))
	    $error = false;
  }
   
  if($error == true){
    $server_error_id=0;
  }

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SERVER_ERROR));
  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<div class="contentContainer">
	<div class="jumbotron">
		<h1 class="text-center"><?php echo $server_error_title[$server_error_id]; ?> <br class="visible-xs"><small><font color="red">Error <?php echo $server_error_number[$server_error_id]; ?></font></small></h1>
		<h4 class="text-center">
			<?php echo $server_error_text[$server_error_id]; ?>
		</h4>
	</div>
    <div class="clearfix"></div>	
	<div class="buttonSet">
		<span class="buttonAction"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?></span>
	</div>	
</div>		

<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Edited by Tsimi

Share this post


Link to post
Share on other sites

@@vampirehunter

 

Yep, can confirm. Works with BS. Got that installed in my shop.

Not really sure about the 500 Internal Error message though but any other error that I could test shows just fine.

Edited by Tsimi

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

×