Opencart 3完美静态化

、去除url中分类目录

1、修改catalog文件夹下,controller > product > category.php

'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)

删除其中的 “ . $this->request->get[‘path’] ” 改为如下:

‘href’ => $this->url->link(‘product/product’, ‘path=’ . ‘&product_id=’ . $result[‘product_id’] . $url)

2、修改catalog文件夹下,controller > startup > seo_url.php
大概在第82行至86行:

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

						unset($data[$key]);
					}
修改为:
if ($query->num_rows && $query->row['keyword']) {
                        if($key == 'product_id'){
                            $url = '/' . $query->row['keyword'];
                        }else{
                            $url .= '/' . $query->row['keyword'];
                        }

                        unset($data[$key]);
                    }

二、URL静态化

1、修改catalog文件夹下,controller > startup > seo_url.php

找到
unset($data[$key]);
				}
在其后增加:
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]);
                    }
                }

2、数据库查询
在数据库中,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/recurring', 'recurring.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');