Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

URL_rewrite problem


genata93

Recommended Posts

I am trying to optimise my oscommerce. Until now everything is going well but i have problem generating my optimised URLs. The code I entered works fine with category and subcategory but when it comes to sub-subcategory the URL is changing but it doesn't visualises the page of the sub-subcategory. I would appreciate some help with this.

 

Here is my URL_rewrite function

function URL_rewrite($url) {
 global $languages_id;
 $matches = array();
 if(preg_match("/cPath=([0-9]*)_?([0-9]+)?_?([0-9]+)?(&products_id=)?([0-9]+)?(.*)?/", $url, $matches)>0 && preg_match("/action=/", $url)==0) {
   // намира име на категория
   if(isset($matches[1])) {
     $cat_id = $matches[1];
     $cat_query = tep_db_query("select categories_id, categories_name from " . TABLE_CATEGORIES_DESCRIPTION . "
       where categories_id = '" . (int)$cat_id  . "' and language_id = '" . (int)$languages_id . "' limit 1");
     $cat_string = tep_db_fetch_array($cat_query);
     $cat_string = remove_accent(URL_safe($cat_string['categories_name']));
   }
   // намира име на подкатегория
   if(isset($matches[2])) {
     $subcat_id = $matches[2];
     $cat_query = tep_db_query("select categories_id, categories_name from " . TABLE_CATEGORIES_DESCRIPTION . "
       where categories_id = '" . (int)$subcat_id . "' and language_id = '" . (int)$languages_id . "'  limit 1");
     $subcat_string = tep_db_fetch_array($cat_query);
     $subcat_string = remove_accent(URL_safe($subcat_string['categories_name']));
   }
//намира име на 3та категория
if(isset($matches[3])) {
     $sucat_id = $matches[3];
     $cat_query = tep_db_query("select categories_id, categories_name from " . TABLE_CATEGORIES_DESCRIPTION . "
       where categories_id = '" . (int)$sucat_id . "' and language_id = '" . (int)$languages_id . "'  limit 1");
     $sucat_string = tep_db_fetch_array($cat_query);
     $sucat_string = remove_accent(URL_safe($sucat_string['categories_name']));
   }
   // намира име на продукт
   if(isset($matches[5])) {
     $prod_id = $matches[5];
     $prod_query = tep_db_query("select products_name, products_id from " . TABLE_PRODUCTS_DESCRIPTION . "
       where products_id = '" . (int)$prod_id . "' and language_id = '" . (int)$languages_id . "'  limit 1");
     $prod_string = tep_db_fetch_array($prod_query);
     $prod_string = remove_accent(URL_safe($prod_string['products_name']));
   }
   // допълнителни данни
   if(isset($matches[6])) {
     $extras = $matches[6];
     // изтрива излишните знаци &
     $extras = substr($extras, 1);
   }

   // почистване на index.php от URL
   if(preg_match("/(.*)index\.php/", $url)>0) {
     $url = preg_replace("/index\.php.*/", "", $url);
   }

   // почистване на product_info.php от URL
   if(preg_match("/(.*)product_info\.php/", $url)>0) {
     $url = preg_replace("/product_info\.php.*/", "", $url);
   }

   // сглобява ново URL
   if(isset($cat_string) && $cat_string != "") {
     $url .= $cat_string."-c".$cat_id;

     // добавя низ за подкатегория
     if(isset($subcat_string) && $subcat_string != "") {
       $url .= "/".$subcat_string."-s".$subcat_id;
     }

  if(isset($sucat_string) && $sucat_string != "") {
       $url .= "/".$sucat_string."-u".$sucat_id;
     }

     // добавя име на продукт
     if(isset($prod_string) && $prod_string != "") {
       $url .= "/".$prod_string."-p".$prod_id;
     }

     // добавя допълнителни данни
     if(isset($extras) && $extras != "") {
       $url .= "/?".$extras;
     }
   }
 } else if(preg_match("/products_id=([0-9]+)(.*)?/", $url, $matches)>0 && preg_match("/action=/", $url)==0) {
   // намира име на продукт
   if(isset($matches[1])) {
     $prod_id = $matches[1];
     $prod_query = tep_db_query("select products_name, products_id from " . TABLE_PRODUCTS_DESCRIPTION . "
       where products_id = '" . (int)$prod_id . "' and     language_id = '" . (int)$languages_id . "' limit 1");
     $prod_string = tep_db_fetch_array($prod_query);
     $prod_string = remove_accent(URL_safe($prod_string['products_name']));
   }
   // допълнителни данни
   if(isset($matches[2])) {
     $extras = $matches[2];
     // изтрива излишните знаци &
     $extras = substr($extras, 1);
   }

   // почистване на product_info.php от URL
   if(preg_match("/(.*)product_info\.php/", $url)>0) {
     $url = preg_replace("/product_info\.php.*/", "", $url);
   }

   // сглобява ново URL
   if(isset($prod_string) && $prod_string != "") {
     $url .= $prod_string."-p".$prod_id;
   }

   // добавя допълнителни данни
   if(isset($extras) && $extras != "") {
     $url .= "/?".$extras;
   }
 } // else

 return $url;
}

 

and here is my .htaccess code

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule [^/]+-c([0-9]+)/[^/]+-s([0-9]+)/[^/]+-p([0-9]+)/? /product_info.php?cPath=$1_$2&products_id=$3 [NC,L,QSA]
RewriteRule [^/]+-c([0-9]+)/[^/]+-p([0-9]+)/? /product_info.php?cPath=$1&products_id=$2 [NC,L,QSA]
RewriteRule [^/]+-c([0-9]+)/[^/]+-s([0-9]+)/? /?cPath=$1_$2 [NC,L,QSA]
RewriteRule [^/]+-p([0-9]+)/? /product_info.php?products_id=$1 [NC,L,QSA]
RewriteRule [^/]+-c([0-9]+)/?$ /?cPath=$1 [NC,L,QSA]
RewriteRule [^/]+-c([0-9]+)/[^/]+-s([0-9]+)/[^/]+-u([0-9]+)/[^/]+-p([0-9]+)/? /product_info.php?cPath=$1_$2_$3&products_id=$4 [NC,L,QSA]
RewriteRule [^/]+-c([0-9]+)/[^/]+-s([0-9]+)/[^/]+-u([0-9]+)/? /?cPath=$1_$2_$3 [NC,L,QSA]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...