X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Custom 404 Error Search Page (https://forum.x-cart.com/showthread.php?t=1471)

usermike 02-11-2003 09:08 AM

Custom 404 Error Search Page
 
This script is based on the search.php file in the /customer directory.

search404.php is a custom 404 error page that no site should be without. It is designed to parce the url and take the keywords that it finds and create a custom results page for your customers.

For instance, say your old site had the page, www.yoursite.com/computer/printer/hp.htm. This script will take the url and create the following keywords: computer, printer, and hp. Then it will perform a custom search and the 404 error page people will see is the search results for these keywords.

So, URL's that didn't exist before now exist with custom tailored results. If it finds no results, it will redirect the users to your main page (or whatever you specify).

This is very good if you had old placements in search engines that you don't want to go to waste.

Paste this code into a file and place it next to search.php in the /customer directory.

Code:

<?

#
# $Id: search404.php,v 1.35 2003/2/11 12:00:00 mweiss Exp $
#

require "../smarty.php";
require "../config.php";
@include "./https.php";
require "./auth.php";
require "../include/categories.php";

  //add pieces or uri to array
  $pieces = explode('/', strtolower($REQUEST_URI));
  // eliminate doubles
  $pieces = array_unique($pieces);

  // Depending on the structure your old site had you might want
  // to change the value of $i.  For instance, in
  // www.yoursite.com/customer/chairs/bar/stools.html
  //  $pieces[0] will hold 'customer'
  //  so $i should be 1.
  $i = 1;
  // page to redirect page if no results are found
  $redir_page = "/customer/home.php";
  $oldkeywords_prod = '';
  $oldkeywords_desc = '';
  $length =  count($pieces);
  while ($i < $length) {
    // strings you would like to replace
    // here, I take out the extensions of pages that people
    // might enter from my old website
    $dummy = $pieces[$i];
    $patterns[0] = '/.htm/';
    $patterns[1] = '/.html/';
    $patterns[2] = '/.php/';
    $patterns[3] = '/.asp/';
    // replace the abov extensions with nothing
    $replacements[0] = '';
    $replacements[1] = '';
    $replacements[2] = '';
    $replacements[3] = '';
    // replace all the instances of 'patterns' with 'replacements' in dummy.
    $pieces[$i] = preg_replace($patterns, $replacements, $dummy);
    if($i == ($length-1))
    {
      $oldkeywords_prod .= $pieces[$i];
      $oldkeywords_desc .= $pieces[$i];
    }
    else
    {
      //build our product query
      $oldkeywords_prod .= $pieces[$i] . "%' OR $sql_tbl[products].product like '%";
      //build our description query
      $oldkeywords_desc .= $pieces[$i] . "%' OR $sql_tbl[products].descr like '%";
    }
    $i++;
  }

        //begin code from search.php
        $price_condition = $price_search_1?" AND $sql_tbl[pricing].price>='$price_search_1'":"";
        $price_condition .= $price_search_2?" AND $sql_tbl[pricing].price<='$price_search_2'":"";
        $sort_by_price = $price_condition?" ORDER BY price":"";

        $price_substring = $price_search_1?"&price_search_1=".urlencode($price_search_1):"";
        $price_substring .= $price_search_2?"&price_search_2=".urlencode($price_search_2):"";

        $search_category = addslashes(array_pop(func_query_first("select category from $sql_tbl[categories] where categoryid='$in_category'")));

        //substitute in our new strings for the query
        $search_query = "($sql_tbl[products].product like '%$oldkeywords_prod%' or $sql_tbl[products].descr like '%$oldkeywords_desc%') and $sql_tbl[categories].category like '$search_category%' and $sql_tbl[products].forsale='Y' $price_condition ".$sort_by_price;

        if ($current_area == "C") {
                $membership_condition = " AND ($sql_tbl[categories].membership='". $user_account['membership']."' OR $sql_tbl[categories].membership='') ";
        } else {
            $membership_condition = "";
        }
       
        //substitute in our new strings for the query
        $search_query_count = "select count(*) from $sql_tbl[products], $sql_tbl[pricing], $sql_tbl[categories] where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[pricing].quantity=1 and $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid $membership_condition and ($sql_tbl[pricing].membership='". $user_account['membership']."' or $sql_tbl[pricing].membership='') and ($sql_tbl[products].product like '%$oldkeywords_prod%' or $sql_tbl[products].descr like '%$oldkeywords_desc%') and $sql_tbl[categories].category like '$search_category%' and $sql_tbl[products].forsale='Y' $price_condition ";

        $total_products_in_search =  array_pop(func_query_first($search_query_count));

        if ($total_products_in_search < 1){
        //if it doesn't find anything, redirect them to the main page
        header("Location: ".$redir_page);
        exit();
        }

#
# Navigation code
#
        $objects_per_page = $config["General"]["products_per_page"];

        $total_nav_pages = ceil($total_products_in_search/$config["General"]["products_per_page"])+1;
        require "../include/navigation.php";

        $smarty->assign("products",func_search_products($search_query, $user_account['membership'],$first_page,$total_products_in_search));

        $smarty->assign("navigation_script","search404.php?substring=".urlencode($substring)."&in_category=$in_category".$price_substring);

        $HTTP_GET_VARS["substring"] = stripslashes($HTTP_GET_VARS["substring"]);

        $smarty->assign("main","search");



$smarty->display("customer/home.tpl");
?>


jpsowin 02-11-2003 09:23 AM

Wow, great idea! I'll have to try it...

funkydunk 02-12-2003 03:42 AM

Nice script 8)

I tend to use a different error reporting script but it essentially does the same thing.

ambermoon 03-25-2003 12:19 AM

not working
 
for some reason this script is not working with me

any sugestions ?

need300z 06-18-2003 07:53 AM

Ok i created a file called bettersearch.php pasted the above code into it and ftp'd the file into the same directory as search.php but for some reason the new file doesn't work? how do i get it to work.

RazorWriter 06-28-2003 11:56 AM

I'm having the same problem with this script. How do we get it to work? I don't understand how the search script knows about this file. Help?

adpboss 06-28-2003 05:01 PM

Someone please help.

I would love to be able to use this script as well.

RazorWriter 07-25-2003 09:34 AM

Funkydunk,
would you be willing to share the script that you are using to acheive this effect?

*We cannot get this one to work* and it's very important (for me) that our x-cart store capture all the traffic that is being achieved by our old site's Google rankings. I'd be willing to pay if you were cool with it.

adpboss 11-27-2003 03:49 PM

Anyone got one of these?

I will kick in some cash. It is needed now more than ever....

DogByteMan 07-31-2004 07:57 PM

adpboss.... did you, or anyone who reads this, get this to work. If so, how?


All times are GMT -8. The time now is 06:25 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.