关于url重写,伪静态问题

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

如:ecshop.com/goods_123.html。
问题:怎么可以将goods改为每个商品的名称?

回答:
帮顶同求不过除非商品是英文 不然就太乱了

我也遇到这个问题了....高手出来帮忙解答一下

英文外贸网站,不会出现中文的。昨天等不到我自己找了一个:
在include/lib_commom.php里面,把下面这段function build_uri($app, $params, $append = '', $page = 0, $keywords = '', $size = 0)
{
static $rewrite = NULL;


if ($rewrite === NULL)
{
$rewrite = intval($GLOBALS['_CFG']['rewrite']);
}


$args = array('cid'=> 0,
'gid'=> 0,
'bid'=> 0,
'acid'=> 0,
'aid'=> 0,
'sid'=> 0,
'gbid'=> 0,
'auid'=> 0,
'sort'=> '',
'order' => '',
);


extract(array_merge($args, $params));


$uri = '';
switch ($app)
{
case 'category':
if (empty($cid))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'category-' . $cid;
if (isset($bid))
{
$uri .= '-b' . $bid;
}
if (isset($price_min))
{
$uri .= '-min'.$price_min;
}
if (isset($price_max))
{
$uri .= '-max'.$price_max;
}
if (isset($filter_attr))
{
$uri .= '-attr' . $filter_attr;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'category.php?id=' . $cid;
if (!empty($bid))
{
$uri .= '&brand=' . $bid;
}
if (isset($price_min))
{
$uri .= '&price_min=' . $price_min;
}
if (isset($price_max))
{
$uri .= '&price_max=' . $price_max;
}
if (!empty($filter_attr))
{
$uri .='&filter_attr=' . $filter_attr;
}


if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}


break;

case 'goods':
if (empty($gid))
{
return false;
}
else
{
$uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid;
}

break;
case 'brand':
if (empty($bid))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'brand-' . $bid;
if (isset($cid))
{
$uri .= '-c' . $cid;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'brand.php?id=' . $bid;
if (!empty($cid))
{
$uri .= '&cat=' . $cid;
}
if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}

break;
case 'article_cat':
if (empty($acid))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'article_cat-' . $acid;
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
if (!empty($keywords))
{
$uri .= '-' . $keywords;
}
}
else
{
$uri = 'article_cat.php?id=' . $acid;
if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
if (!empty($keywords))
{
$uri .= '&keywords=' . $keywords;
}
}
}

break;
case 'article':
if (empty($aid))
{
return false;
}
else
{
$uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
}

break;
case 'group_buy':
if (empty($gbid))
{
return false;
}
else
{
$uri = $rewrite ? 'group_buy-' . $gbid : 'group_buy.php?act=view&id=' . $gbid;
}

break;
case 'auction':
if (empty($auid))
{
return false;
}
else
{
$uri = $rewrite ? 'auction-' . $auid : 'auction.php?act=view&id=' . $auid;
}

break;
case 'snatch':
if (empty($sid))
{
return false;
}
else
{
$uri = $rewrite ? 'snatch-' . $sid : 'snatch.php?id=' . $sid;
}

break;
case 'search':
break;
case 'exchange':
if ($rewrite)
{
$uri = 'exchange-' . $cid;
if (isset($price_min))
{
$uri .= '-min'.$price_min;
}
if (isset($price_max))
{
$uri .= '-max'.$price_max;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'exchange.php?cat_id=' . $cid;
if (isset($price_min))
{
$uri .= '&integral_min=' . $price_min;
}
if (isset($price_max))
{
$uri .= '&integral_max=' . $price_max;
}

if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}

break;
case 'exchange_goods':
if (empty($gid))
{
return false;
}
else
{
$uri = $rewrite ? 'exchange-id' . $gid : 'exchange.php?id=' . $gid . '&act=view';
}

break;
default:
return false;
break;
}

if ($rewrite)
{
if ($rewrite == 2 && !empty($append))
{
$uri .= '-' . urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
}

$uri .= '.html';
}
if (($rewrite == 2) && (strpos(strtolower(EC_CHARSET), 'utf') !== 0))
{
$uri = urlencode($uri);
}
return $uri;
}

更改为以下的:
function build_uri($app, $params, $append = '', $page = 0, $size = 0)
{
static $rewrite = NULL;

if ($rewrite === NULL)
{
$rewrite = intval($GLOBALS['_CFG']['rewrite']);
}

$args = array('cid' => 0,
'gid' => 0,
'bid' => 0,
'acid' => 0,
'aid' => 0,
'sid' => 0,
'gbid' => 0,
'auid' => 0,
'sort' => '',
'order' => '',
);

extract(array_merge($args, $params));
$uri = '';
switch ($app)
{
case 'category':
if (empty($cid))
{
return false;
}
else
{
if ($rewrite)
{
$name = urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
$uri = 'simulation-'.$name.'-' . $cid;
if (isset($bid))
{
$uri .= '-b' . $bid;
}
if (isset($price_min))
{
$uri .= '-min'.$price_min;
}
if (isset($price_max))
{
$uri .= '-max'.$price_max;
}
if (isset($filter_attr))
{
$uri .= '-attr' . $filter_attr;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'category.php?id=' . $cid;
if (!empty($bid))
{
$uri .= '&brand=' . $bid;
}
if (isset($price_min))
{
$uri .= '&price_min=' . $price_min;
}
if (isset($price_max))
{
$uri .= '&price_max=' . $price_max;
}
if (!empty($filter_attr))
{
$uri .='&filter_attr=' . $filter_attr;
}

if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}

break;

case 'goods':
if (empty($gid))
{
return false;
}
else
{

//$uri = $rewrite ? 'goods-' . $gid : 'goods.php?id=' . $gid;
$name = urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
$uri = 'simulation-'.$name.'-g' . $gid;
}

break;
case 'brand':
if (empty($bid))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'brand-' . $bid;
if (isset($cid))
{
$uri .= '-c' . $cid;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'brand.php?id=' . $bid;
if (!empty($cid))
{
$uri .= '&cat=' . $cid;
}
if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}

break;
case 'article_cat':
if (empty($acid))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'article_cat-' . $acid;
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'article_cat.php?id=' . $acid;
if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}

break;
case 'article':
if (empty($aid))
{
return false;
}
else
{
$uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
}

break;
case 'group_buy':
if (empty($gbid))
{
return false;
}
else
{
$uri = $rewrite ? 'group_buy-' . $gbid : 'group_buy.php?act=view&id=' . $gbid;
}

break;
case 'auction':
if (empty($auid))
{
return false;
}
else
{
$uri = $rewrite ? 'auction-' . $auid : 'auction.php?act=view&id=' . $auid;
}

break;
case 'snatch':
if (empty($sid))
{
return false;
}
else
{
$uri = $rewrite ? 'snatch-' . $sid : 'snatch.php?id=' . $sid;
}

break;
case 'search':
break;
case 'exchange':
if ($rewrite)
{
$uri = 'exchange-' . $cid;
if (isset($price_min))
{
$uri .= '-min'.$price_min;
}
if (isset($price_max))
{
$uri .= '-max'.$price_max;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'exchange.php?cat_id=' . $cid;
if (isset($price_min))
{
$uri .= '&integral_min=' . $price_min;
}
if (isset($price_max))
{
$uri .= '&integral_max=' . $price_max;
}

if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}

break;
case 'exchange_goods':
if (empty($gid))
{
return false;
}
else
{
$uri = $rewrite ? 'exchange-id' . $gid : 'exchange.php?id=' . $gid . '&act=view';
}

break;
default:
return false;
break;
}

if ($rewrite)
{
if ($rewrite == 2 && !empty($append)&&$app!='category')//我多加了一个条件
{
$uri .= '-' . urlencode(preg_replace('/[\.|\/|\?|&|\+|\\\|\'|"|,]+/', '', $append));
}

$uri .= '.html';
}
if (($rewrite == 2) && (strpos(strtolower(EC_CHARSET), 'utf') !== 0))
{
$uri = urlencode($uri);
}
return $uri;
}

然后.htaccess也要修改:
RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)\.html$category\.php\?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6&page=$7&sort=$8&order=$9 [QSA,L]
RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)\.html$category\.php\?id=$2&brand=$3&price_min=$4&price_max=$5&filter_attr=$6 [QSA,L]
RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html$category\.php\?id=$2&brand=$3&page=$4&sort=$5&order=$6 [QSA,L]
RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)-([0-9]+)\.html$category\.php\?id=$2&brand=$3&page=$4 [QSA,L]
RewriteRule ^simulation-(.*)-([0-9]+)-b([0-9]+)\.html$category\.php\?id=$2&brand=$3 [QSA,L]
RewriteRule ^simulation-(.*)-([0-9]+)\.html$category\.php\?id=$2 [QSA,L]



RewriteRule ^simulation-(.*)-g([0-9]+)\.html$goods\.php\?id=$2 [QSA,L]

改成你们想要的就可以了

很好啊 这个 是个思路

好教程,EC人才真多....谢谢分享,收藏了

自带的规则就有

ecshop学习资料:http://www.phpally.com

帮顶帮顶

我也遇到这个问题了....高手出来帮忙解答一下