Opencart 3.x generating SEO-Friendly links for 'Search on homepage' and 'admin page'

Working with opencart 3.x. I was thinking of changing .htaccess, seo_url, I wouldn't want to mess with the tables in mysql if it's possible. Three questions I can't find a solution to. I'm stuck on these two, trying to make them SEO friendly & having a block html on the php page. Any help would be nice, thanks.

current link:

https://www.-----.com/index.php?route=product/search&search=...

Q: 1) How to get SEO link to be just

https://www.-----.com/search

admin current link https://www.-----.com/admin/index.php?route=common/dashboard&user_token=...

Q: 2) How to get SEO link to be just

https://www.-----.com/admin/dashboard

Q: 3) How can I create a block html on opencart manually in FZilla? I like write them in the actually files instead of modifying it and screw up the store.


Solution 1:

FRONTEND

For frontend (catalog) I have 2 solutions: long and short.

  1. Long.
  • first, add support for custom urls in catalog/controller/statup/seo_url.php on line 103 after the closing }
else {
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($data['route']) . "' 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 = '';
    }
}

Then run the following MySQL code in your phpMyAdmin. It will populate the custom urls.

INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'product/search', 'search');

You can also add all the other custom urls as well.

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');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/account', 'my-account');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'checkout/cart', 'shopping-cart');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'checkout/checkout', 'checkout');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/login', 'login');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/logout', 'logout');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/order', 'order-history');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/newsletter', 'newsletter');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'product/special', 'specials');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/account', 'affiliates');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/voucher', 'voucher');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'product/manufacturer', 'brands');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'information/contact', 'contact-us');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/return/add', 'request-return');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'information/sitemap', 'sitemap');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/forgotten', 'forgot-password');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/download', 'downloads');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/return', 'returns');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/transaction', 'transactions');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/register', 'create-account');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'product/compare', 'compare-products');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/edit', 'edit-account');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/password', 'change-password');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/address', 'address-book');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'account/reward', 'reward-points');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/edit', 'edit-affiliate-account');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/password', 'change-affiliate-password');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/payment', 'affiliate-payment-options');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/tracking', 'affiliate-tracking-code');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/transaction', 'affiliate-transactions');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/logout', 'affiliate-logout');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/forgotten', 'affiliate-forgot-password');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/register', 'create-affiliate-account');
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'affiliate/login', 'affiliate-login');
  1. Short.

Just install SEO Module URL and set it up. You will have all custom URLs edited automatically for you and you can then customize them as you wish via the admin panel.

enter image description here

SEO Module URL

BACKEND

For backend (admin) OpenCart does not implement SEO Url functionality. You can do it on your own, but it requires a bit more coding to be done.

Basically you need to reproduce the catalog/controller/startup/seo_url.php in admin folder

and register this in system/config/admin.php

$_['action_pre_action'] = array(
...
'startup/seo_url'

You will also need to add the custom urls to the seo_url table in the DB.

INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`) VALUES ('0', '1', 'common/dashboard', 'dashboard');

Hope this helps.