ZenCart产品页入口判断301跳转

ZenCart的伪静态插件将产品名也一起放在了url里,当你改变产品名称的时候就会导致重复页面的出现,因此就需要做301跳转。将多个指向同一个产品的url定向到标准的地址上。代码如下:

//产品页入口判断跳转by caic
$pos = strrpos($_SERVER['REQUEST_URI'],'-p-');
if($pos!==false){
	$products_id = intval(substr($_SERVER['REQUEST_URI'],$pos+3));
	$sql = "select p.products_id, pd.products_name,p.master_categories_id
	          from " . TABLE_PRODUCTS . " p, " .
	                   TABLE_PRODUCTS_DESCRIPTION . " pd
	          where    p.products_status = '1'
	          and      p.products_id = '" . $products_id . "'
	          and      pd.products_id = p.products_id
	          and      pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
	$res = $db->Execute($sql);
	$prourl = zen_href_link(zen_get_info_page($res->fields["products_id"]), 'cPath=' . zen_get_generated_category_path_rev($res->fields["master_categories_id"]) . '&products_id=' . $res->fields["products_id"]);
	$thisurl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	if($thisurl!=$prourl){
	 	Header("HTTP/1.1 301 Moved Permanently");
	 	Header("Location: $prourl");
	 	exit;
	}
}
分享到:更多 ()

抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址