Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Custom 404 Error Search Page

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 02-11-2003, 09:08 AM
 
usermike usermike is offline
 

Advanced Member
  
Join Date: Jan 2003
Posts: 41
 

Default 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"); ?>
Reply With Quote
  #2  
Old 02-11-2003, 09:23 AM
 
jpsowin jpsowin is offline
 

X-Adept
  
Join Date: Sep 2002
Posts: 459
 

Default

Wow, great idea! I'll have to try it...
__________________
Joshua Sowin
...taking things one TPL at a time.
Reply With Quote
  #3  
Old 02-12-2003, 03:42 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Nice script

I tend to use a different error reporting script but it essentially does the same thing.
__________________
ex x-cart guru
Reply With Quote
  #4  
Old 03-25-2003, 12:19 AM
 
ambermoon ambermoon is offline
 

Advanced Member
  
Join Date: Feb 2003
Location: Perth Western Australia
Posts: 72
 

Default not working

for some reason this script is not working with me

any sugestions ?
Reply With Quote
  #5  
Old 06-18-2003, 07:53 AM
 
need300z need300z is offline
 

Member
  
Join Date: May 2003
Posts: 16
 

Default

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.
Reply With Quote
  #6  
Old 06-28-2003, 11:56 AM
  RazorWriter's Avatar 
RazorWriter RazorWriter is offline
 

Advanced Member
  
Join Date: Dec 2002
Location: Arizona, USA
Posts: 50
 

Default

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?
__________________
one day we\'ll all look back at the progress of x-cart like our child grown up and ready to take on the world...
Reply With Quote
  #7  
Old 06-28-2003, 05:01 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Someone please help.

I would love to be able to use this script as well.
Reply With Quote
  #8  
Old 07-25-2003, 09:34 AM
  RazorWriter's Avatar 
RazorWriter RazorWriter is offline
 

Advanced Member
  
Join Date: Dec 2002
Location: Arizona, USA
Posts: 50
 

Default

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.
__________________
one day we\'ll all look back at the progress of x-cart like our child grown up and ready to take on the world...
Reply With Quote
  #9  
Old 11-27-2003, 03:49 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Anyone got one of these?

I will kick in some cash. It is needed now more than ever....
Reply With Quote
  #10  
Old 07-31-2004, 07:57 PM
  DogByteMan's Avatar 
DogByteMan DogByteMan is offline
 

X-Adept
  
Join Date: Mar 2003
Posts: 833
 

Default

adpboss.... did you, or anyone who reads this, get this to work. If so, how?
__________________
Dedicated Server provided by EWD Hosting
X-Cart version 4.1.12
PHP 5.3.2
MySQL server 5.0.87-community
Operation system Linux
Perl 5.008008
dogbytecomputer.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:09 PM.

   

 
X-Cart forums © 2001-2020