opencart 实现全面伪静态

opencart全面伪静态方法 

方法一 
购买插件opencart seo pack pro 
该插件很强大很贵。请自行搜索该资料。 

方法二 
Opencart在开启伪静态功能之后(更改htaccess.txt为.htaccess,在catagory和产品SEO处添加相应的伪静态文字),添加的产品页面和分类页面都可以实现静态化效果,其他页面需要以下方法实现 
编辑catalog/controller/common/seo_url.php 

foreach ($data as $key => $value) { 
if (isset($data['route'])) { 
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) { 
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'"); 

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

unset($data[$key]); 

} elseif ($key == 'path') { 
$categories = explode('_', $value); 

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

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



unset($data[$key]); 

}

这里添加下列代码!!!!!!!!!!!! 



if ($url) { 
unset($data['route']); 

$query = ''; 

if ($data) { 
foreach ($data as $key => $value) { 
$query .= '&' . $key . '=' . $value; 


if ($query) { 
$query = '?' . trim($query, '&'); 



return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query; 
} else { 
return $link; 

}

?> 

需要添加的代码: 

if ($key == 'route') { 
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($value) . "'"); 

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

unset($data[$key]); 



然后在数据库phpmyadmin里SQL-运行 SQL 查询-执行 (如执行错误,请检查url_alias名称是否有前缀,例:oc_url_alias,请在自行添加前缀) / 或找到url_alias手动输入 

INSERT INTO url_alias (query, keyword) VALUES ('common/home', ''); 
INSERT INTO url_alias (query, keyword) VALUES ('account/wishlist', 'wishlist'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/account', 'my-account'); 
INSERT INTO url_alias (query, keyword) VALUES ('checkout/cart', 'shopping-cart'); 
INSERT INTO url_alias (query, keyword) VALUES ('checkout/checkout', 'checkout'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/login', 'login'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/logout', 'logout'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/order', 'order-history'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/newsletter', 'newsletter'); 
INSERT INTO url_alias (query, keyword) VALUES ('product/special', 'specials'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/account', 'affiliates'); 
INSERT INTO url_alias (query, keyword) VALUES ('checkout/voucher', 'gift-vouchers'); 
INSERT INTO url_alias (query, keyword) VALUES ('product/manufacturer', 'brands'); 
INSERT INTO url_alias (query, keyword) VALUES ('information/contact', 'contact-us'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/return/insert', 'request-return'); 
INSERT INTO url_alias (query, keyword) VALUES ('information/sitemap', 'sitemap'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/forgotten', 'forgot-password'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/download', 'downloads'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/return', 'returns'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/transaction', 'transactions'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/register', 'create-account'); 
INSERT INTO url_alias (query, keyword) VALUES ('product/compare', 'compare-products'); 
INSERT INTO url_alias (query, keyword) VALUES ('product/search', 'search'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/edit', 'edit-account'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/password', 'change-password'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/address', 'address-book'); 
INSERT INTO url_alias (query, keyword) VALUES ('account/reward', 'reward-points'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/edit', 'edit-affiliate-account'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/password', 'change-affiliate-password'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/payment', 'affiliate-payment-options'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/tracking', 'affiliate-tracking-code'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/transaction', 'affiliate-transactions'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/logout', 'affiliate-logout'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/forgotten', 'affiliate-forgot-password'); 
INSERT INTO url_alias (query, keyword) VALUES ('affiliate/register', 'create-affiliate-account'); 

INSERT INTO url_alias (query, keyword) VALUES ('affiliate/login', 'affiliate-login');


以下转自: http://www.php100.com/html/program/apache/2013/0905/5493.html

1、开启rewrite_module:鼠标左键点击右下角wamp运行图标,在选项中Apache->Apache模块中找到rewrite_module,点击即开启本模块。wamp会自动重启服务。

opencart 实现全面伪静态_第1张图片

2、修改httpd.conf文件:同样,在Apache->找到httpd.conf,点击即可打开httpd.conf文件。找到:

AllowOverride None

修改为:

AllowOverride All

然后重启wamp的所有服务。

3、这时已经支持.htaccess文件来重写了,写自己的.htaccess放到目录下测试吧。


你可能感兴趣的:(伪静态,opencart)