sitefire Posted November 20, 2009 Posted November 20, 2009 I have been playing with a contrib called easy seo urls and have got it working, along with creating a correct .htaccess but need to add the capability of adding one more category as our site has 1 main category, 1 sub category and 1 sub sub category for our products. The contrib now only allows for 2 categories. Once everything is up and running I will post the completed contrib with the .htaccess file for an apache server. Here is a sample of the code: function URL_rewrite($url) { $matches = array(); if(preg_match("/cPath=([0-9]+)_?([0-9]+)?(&products_id=)?([0-9]+)?/", $url, $matches)>0 && preg_match("/action=/", $url)==0) { // fetch category name 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 . "' limit 1"); $cat_string = tep_db_fetch_array($cat_query); $cat_string = URL_safe($cat_string['categories_name']); } // fetch subcategory 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 . "' limit 1"); $subcat_string = tep_db_fetch_array($cat_query); $subcat_string = URL_safe($subcat_string['categories_name']); } // fetch product name if(isset($matches[4])) { $prod_id = $matches[4]; $prod_query = tep_db_query("select products_name, products_id from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$prod_id . "' limit 1"); $prod_string = tep_db_fetch_array($prod_query); $prod_string = URL_safe($prod_string['products_name']); } // get rid of the index page in URL if(preg_match("/(.*)index\.php/", $url)>0) { $url = preg_replace("/index\.php.*/", "", $url); } // get rid of the products page in URL if(preg_match("/(.*)product_info\.php/", $url)>0) { $url = preg_replace("/product_info\.php.*/", "", $url); } // build new URL if(isset($cat_string) && $cat_string != "") { $url .= $cat_string."-c".$cat_id; // append subcat string if(isset($subcat_string) && $subcat_string != "") { $url .= "/".$subcat_string."-s".$subcat_id; } // append product title if(isset($prod_string) && $prod_string != "") { $url .= "/".$prod_string."-p".$prod_id; } } return $url."/"; } else { return $url; } } // Make categories and product titles safe for URLs function URL_safe($str) { $str = strtolower($str); $str = preg_replace("/[^a-z0-9\-]+/i","-",$str); $str = urlencode($str); return $str; }
Recommended Posts
Archived
This topic is now archived and is closed to further replies.