opencart3.0之伪静态设置
原标题:opencart3.0之伪静态设置
导读:
本篇文章为大家讲述如何设置伪静态,既然说到伪静态,这里就顺便提一下它的用处:主要好处就是为了迎合搜索引擎的抓取,以此对搜索引擎表示友好,达到更佳的 SEO 优化效果,其次也就是...
文章目录 [+]
-
本篇文章为大家讲述如何设置伪静态,既然说到伪静态,这里就顺便提一下它的用处:主要好处就是为了迎合搜索引擎的抓取,以此对搜索引擎表示友好,达到更佳的 SEO 优化效果,其次也就是明确了网站的的 URL 链接,方便了用户的浏览、输入、以及传播等。
-
下面进入本篇文章的正题:
系统设置 -> 网店设置 -> 服务器设置 -> 启用伪静态在启用伪静态的时候 我们可以看到它提示了 服务器必须支持Apache Rewrite Mod 功能,也就是appache服务器要开启mod_rewrite。
然后还需要将htaccess.txt文件 重命名为.htaccess文件。其实htaccess.txt文件 就是opencart自带写好的伪静态规则文件,不过要修改成 .htaccess 才能生效。htaccess文件只有apache服务器有效。
修改网站根目录下的.htaccess.txt为.htaccess文件,在windows环境下去掉.txt时,会有一个错误提示导致无法修改,我整合了几种简单的方式来修改:
①用记事本打开htaccess.txt文件,然后点击文件–另存为,在文件名窗口输入”.htaccess”,注意文件名需要包含英文引号,然后点击保存就行了。
②在网站根目录的system文件夹下有一个.htaccess文件,直接把它复制出来 ,然后将htaccess.txt的内容复制一遍到.htaccess文件里
③进入cmd命令 窗口,通过cd切换当刚建立htaccess.txt文件的文件夹,然后输入命令:rename htaccess.txt .htaccess ,然后点击键盘Enter键即可。
-
做完以上步骤 ,我们需要去设置的SEO关键词 ,
下图是商品的seo关键词设置示列(分类、品牌、信息管理等也可以设置seo关键词)4.这里给大家补充一下opencart在Nginx服务器的伪静态设置,Nginx下设置伪静态方法与Apache差不多,直接在nginx.conf (或者在对应的*.conf) 中找到需设置伪静态规则的服务器对应字段,在server{ location/{ } }中添加以下代码:(添加后重启Nginx服务,www.abc.com记得要换成自己的网站域名)
if ($host != 'www.abc.com') { rewrite ^/(.*)$ http://www.abc.com/$1 permanent; } try_files $uri @opencart; } location @opencart { rewrite ^/(.+)$ /index.php?_route_=$1 last; } location /admin/ { index index.php; } location ~* (\.(tpl|ini))$ { deny all;
5.这里再补充一下如何全站设置伪静态:首先我们打开 catalog\controller\startup\seo_url.php 文件,然后找到下面第一段代码,然后加上后面的代码
elseif ($key == 'path') { $categories = explode('_', $value); foreach ($categories as $category) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); if ($query->num_rows && $query->row['keyword']) { $url .= '/' . $query->row['keyword']; } else { $url = ''; break; } } unset($data[$key]); } //找到上面的代码位置(一般在103行),添加下面的代码 elseif ($key == 'route') { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "'"); if ($query->num_rows) { $url .= '/' . $query->row['keyword']; unset($data[$key]); } }
添加代码之后打开数据库执行以下sql语句添加伪静态关键词,这样就完成了全站的伪静态设置。
INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'common/home', ''); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/wishlist', 'wishlist.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/account', 'my-account.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'checkout/cart', 'shopping-cart.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'checkout/checkout', 'checkout.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/login', 'login.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/logout', 'logout.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/order', 'order-history.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/newsletter', 'newsletter.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'product/special', 'specials.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/account', 'affiliates.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'checkout/voucher', 'gift-vouchers.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'product/manufacturer', 'brands.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'information/contact', 'contact-us.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/return/insert', 'request-return.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'information/sitemap', 'sitemap.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/forgotten', 'forgot-password.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/download', 'downloads.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/return', 'returns.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/transaction', 'transactions.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/register', 'create-account.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'product/compare', 'compare-products.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'product/search', 'search.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/edit', 'edit-account.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/password', 'change-password.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/address', 'address-book.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/reward', 'reward-points.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/edit', 'edit-affiliate-account.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/password', 'change-affiliate-password.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/payment', 'affiliate-payment-options.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/tracking', 'affiliate-tracking-code.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/transaction', 'affiliate-transactions.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/logout', 'affiliate-logout.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/forgotten', 'affiliate-forgot-password.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/register', 'create-affiliate-account.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'affiliate/login', 'affiliate-login.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/voucher', 'account-voucher.html'); INSERT INTO oc_seo_url (store_id, language_id, query, keyword) VALUES (0, 1, 'account/return/add', 'account-return-add.html');
有好的文章希望我们帮助分享和推广,猛戳这里我要投稿