开源一个B2B多域名独立SEO站点的伪静态规则

该多站多域名服务器集群独立SEO伪静态规则由作者“清心醉”独立编写,转发请注明出处!

您对开源的尊重,让更多一个人尊重源代码的原始作者!

function rewrite($link) {
$url_info = parse_url(str_replace(‘&’, ‘&’, $link));
$url = ”;
$product_id=null; #–定义产品ID  //平台直接跳转
$data = array();
parse_str($url_info[‘query’], $data);
foreach ($data as $key => $value) {
if (isset($data[‘ipanying’])) {
if (($data[‘ipanying’] == ‘product/product’ && $key == ‘product_id’)
|| (($data[‘ipanying’] == ‘product/manufacturer/info’ || $data[‘ipanying’] == ‘product/product’) && $key == ‘manufacturer_id’)
|| ($data[‘ipanying’] == ‘information/information’ && $key == ‘information_id’)
|| ($data[‘ipanying’] == ‘ckz/word/word’ && $key==’word_id’ )  ) {

if ($data[‘ipanying’] == ‘product/product’ && $key == ‘product_id’ && STORE_ID==0){ #–如果为产品ID并且是平台的话
$product_id=$value;
}
$query = $db->query(“SELECT * FROM ” . DB_PREFIX . “url_alias WHERE `query` = ‘” . $db->escape($key . ‘=’ . (int)$value) . “‘”);

if ($query->num_rows && $query->row[‘keyword’]) {
$url = ‘/’ . $query->row[‘keyword’];

unset($data[$key]);
}
} elseif ($key == ‘path’) {
$categories = explode(‘_’, $value);

foreach ($categories as $category) {
$query = $db->query(“SELECT * FROM ” . DB_PREFIX . “url_alias WHERE `query` = ‘category_id=” . (int)$category . “‘”);

if ($query->num_rows && $query->row[‘keyword’]) {
$url = ‘/’ . $query->row[‘keyword’];
} else {
$url = ”;

break;
}
}

unset($data[$key]);

} elseif ($key == ‘ipanying’) {
$query = $db->query(“SELECT * FROM ” . DB_PREFIX . “url_alias WHERE `query` = ‘” . $db->escape($value) . “‘”);
if ($query->num_rows) {
$url = ‘/’ . $query->row[‘keyword’];
unset($data[$key]);
}
}
}
}

if ($url) {
unset($data[‘ipanying’]);

$query = ”;

if ($data) {
foreach ($data as $key => $value) {
$query .= ‘&’ . rawurlencode((string)$key) . ‘=’ . rawurlencode((string)$value);
}

if ($query) {
$query = ‘?’ . str_replace(‘&’, ‘&’, trim($query, ‘&’));
}
}

//if (STORE_ID==0 && !empty($product_id)){
if (STORE_ID!=0){ #-如果非平台
$product_url=$model->getStoreUrl(STORE_ID); #-强制获取店铺URL
$url=str_replace(‘/’,”,$url);  #– 提取URL
return $product_url. $url . $query; #– 返回拼接URL
}  else if(STORE_ID==0 && !empty($product_id)){ #如果是平台并且有产品调用(因为产品是二级域名)
$store_id=$model->getProductAsStore($product_id); #– 获取产品对应的店铺ID
$product_url=$model->getStoreUrl($store_id); #– 根据店铺ID获取网站URL
$url=str_replace(‘/’,”,$url);  #– 因为店铺URL中已经存在‘/’符号,所以进行删除
return $product_url. $url . $query; #– 返回拼接URL
}  else {
return $url_info[‘scheme’] . ‘://’ . $url_info[‘host’] . (isset($url_info[‘port’]) ? ‘:’ . $url_info[‘port’] : ”) . str_replace(‘/index.php’, ”, $url_info[‘path’]) . $url . $query; #-否则就是平台而且无PRODUCT产品的时候的平台直属URL
}

} else {
return $link;
}
}

 

调用的模型类中其实就是对数据库的操作!

$store_id=$model->getProductAsStore($product_id); #– 获取产品对应的店铺ID
$product_url=$model->getStoreUrl($store_id); #– 根据店铺ID获取网站URL

根据自己定义的实际URL来进行

该处代码为平台显示二级域名的产品时所产生伪静效果

 

 

This entry was posted in C++.

发表评论

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: