opencart伪静态方法_外贸培训_莆田外贸-莆田外贸培训 -


莆田外贸

查看: 5504|回复: 0
打印 上一主题 下一主题

[opencart] opencart伪静态方法

[复制链接]

484

主题

603

帖子

4549

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4549

生肖虎莆常住居民

QQ
跳转到指定楼层
楼主
发表于 2016-5-24 21:35:00 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
Opencart在开启伪静态功能


用ftp链接网站,把根目录文件 .htaccess.txt 改为 .htaccess   即去掉 .txt

之后,添加的产品页面和分类页面都可以实现静态化效果,其他页面需要以下方法实现
编辑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;
}
}        
}
?>

需要添加以下代码:

elseif ($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');


收藏收藏 转播转播
赞助我们:
微信
外贸建站、外贸培训、企业建站、网络推广、服务器域名销售、程序二次开发、微信营销。QQ1806098280
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台



首 页|关于我们|广告联系|Archiver|手机版|百姓活动Q群:195562840|品牌招募|友情申请

Copyright © 2012-2015 莆田百姓通(http://www.ptbaixing.com) 版权所有 All Rights Reserved.

免责声明: 本网不承担任何由内容提供商提供的信息所引起的争议和法律责任。

Powered by Discuz! X3.2 技术支持: 莆田百姓电商 闽ICP备14001707号-1    QQ

快速回复 返回顶部 返回列表