这次针对OC 2.x版本说说伪静态的设置,本人OC系统2.3.0.2 ,至于其他OC版本如1.5.6.4 ,方法略有不同,网上已经写了很多,可以自行搜索。
--------------------华丽分界线------------------------
伪静态条件:
需要开启服务器伪静态模式:rewrite_module,不懂的自行搜索,一般服务器都支持伪静态功能。
OC的伪静态
1. 将.htaccess.txt用notepad++等编辑器改名为.htaccess,如果网站放在二级目录RewriteBase /后面加上二级目录的名称。
如:网站放在子目录如shop下,RewriteBase /改为RewriteBase /shop/
2.在System -> Settings -> [ Edit ] -> Sever中将Use SEO URL's 改为 yes
--------------------华丽分界线------------------------
方法一
购买插件opencart seo pack pro 该插件很强大很贵。请自行搜索该资料。
方法二
Opencart在开启伪静态功能之后, Opencart每个分类和产品页url伪静态都可以自己填写,
进入后台 Catalog==>products==>找到需要编辑的产品
编辑它,选择Data项,找到SEO Keyword, 输入你想要的关键词
例如 iphone-6s.html 在这里填写你要的字符串就好了
现在去首页在点击这个产品 URL 变成 http://yoursite.com/opencart/desktops/iphone-6s.html
产品数量很多的话,会非常麻烦,可以使用 SEO Script Generator插件--------------------华丽分界线------------------------
其他页面需要以下方法,适用技术爱好者,手动修改
需要修改
一个文件 ,catalog/controller/startup/seo_url.php
一个数据库表,oc_url_alias 这个表
1、修改源文件:catalog/controller/startup/seo_url.php,大概103行,添加如下代码:
else{ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($data['route']) . "'"); if ($query->num_rows) { $url .= '/' . $query->row['keyword']; unset($data[$key]); } }
2、然后在数据库phpmyadmin里SQL-运行 SQL 查询-执行
INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('common/home', 'index.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/wishlist', 'wishlist.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/account', 'my-account.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('checkout/cart', 'shopping-cart.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('checkout/checkout', 'checkout.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/login', 'login.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/logout', 'logout.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/order', 'order-history.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/newsletter', 'newsletter.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('product/special', 'specials.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/account', 'affiliates.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('checkout/voucher', 'gift-vouchers.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('product/manufacturer', 'brands.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('information/contact', 'contact.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/return/insert', 'request-return.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('information/sitemap', 'sitemap.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/forgotten', 'forgot-password.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/download', 'downloads.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/return', 'returns.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/transaction', 'transactions.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/register', 'register.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('product/compare', 'compare-products.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('product/search', 'search.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/edit', 'edit-account.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/password', 'change-password.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/address', 'address-book.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('account/reward', 'reward-points.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/edit', 'edit-affiliate-account.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/password', 'change-affiliate-password.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/payment', 'affiliate-payment-options.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/tracking', 'affiliate-tracking-code.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/transaction', 'affiliate-transactions.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/logout', 'affiliate-logout.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/forgotten', 'affiliate-forgot-password.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/register', 'create-affiliate-account.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('affiliate/login', 'affiliate-login.html'); INSERT INTO oc_url_alias (`query`, `keyword`) VALUES ('common/currency/currency', 'common-currency-currency.html');
好了以上就可完成伪静态
只要在地址栏中输入 http://127.0.0.1/opencart/加上你 数据库keyword的值就可以访问对应页面了。
--------------------------------------------------------------------------
由于,页面上很多使用 固定地址,所以我们要去代码中将 地址改掉, 一般的地址都在/opencart/catalog/controller
先看 common 目录下的
我们先修改首页的导航: Home Log Off Account Basket Checkout
这几个地址都在 /opencart/catalog/controller/common/header.php
$this->data['home'] = HTTP_SERVER . 'index.php?route=common/home'; $this->data['special'] = HTTP_SERVER . 'index.php?route=product/special'; $this->data['contact'] = HTTP_SERVER . 'index.php?route=information/contact'; $this->data['sitemap'] = HTTP_SERVER . 'index.php?route=information/sitemap'; $this->data['account'] = HTTPS_SERVER . 'index.php?route=account/account'; $this->data['logged'] = $this->customer->isLogged(); $this->data['login'] = HTTPS_SERVER . 'index.php?route=account/login'; $this->data['logout'] = HTTP_SERVER . 'index.php?route=account/logout'; $this->data['cart'] = HTTP_SERVER . 'index.php?route=checkout/cart'; $this->data['checkout'] = HTTPS_SERVER . 'index.php?route=checkout/shipping';
例如 home 我们可以修改成
$this->data['home'] = HTTP_SERVER . 'index.html';
我不是很建议把地址直接修改成 index.html,如果日后你又要还原,就麻烦了,我们可以在根目录中的 config.php 中定义 define(‘HOME’, ’index.html’);
在header.php中就可以
$this->data['home' ]= HTTP_SERVER . HOME;
日后只要的config.php中修改定义,就可以了
define('HOME', 'index.php?route=common/home');