SEO URLs in OpenCartA free open-source CMS for online stores, written in PHP with a MySQL/MariaDB database. Everything that is not part of the core is added through extensions. More in the glossary → rely on two things: the table with links between a "keyword" and "query parameters", and the startup controllerCode that receives a request and prepares data. More in the glossary → seo_url. On an incoming request, this controller converts startup/seo_url into regular GET parameters. When the store generates a link, the same controller performs the reverse conversionThe share of visitors who completed a goal, usually a purchase. Calculated as orders ÷ visits × 100%. More in the glossary → through the / method. If you understand how seo_url works in OpenCart internally, you can explain any 404 on a "pretty" address or any rewrite() tail in a link.?route=…
Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ.
What does the seo_url table store in 3.0 and 4.1?
The table (the prefix depends on the installation) stores the correspondence between a keyword in the address and the parameter it replaces. Each row is tied to a store (oc_seo_url) and a language (store_id), so a single product in a multilingual store has several rows, one per language. The structure differs significantly between versions, and this is visible directly in the controller code: in 3.0 it reads the language_id field, while in 4.1 it works with the query, key, and value fields.sort_order
| Aspect | OpenCart 3.0 | OpenCart 4.1 |
|---|---|---|
| What is replaced | A row of the form | The pair + , for example and |
| Keyword | | |
| Order of segments in the path | Determined by the order of parameters in the link's query string (for example, before ); there is no separate sort field | The field |
| Parameters supported "out of the box" | , , , | Any GET parameter that has a row |
Examples of records for each version:
-- OpenCart 3.0: виробник Apple для магазину 0, мова 1
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `query`, `keyword`)
VALUES (0, 1, 'manufacturer_id=8', 'apple');
-- OpenCart 4.1: сторінка контактів як окремий маршрут
INSERT INTO `oc_seo_url` (`store_id`, `language_id`, `key`, `value`, `keyword`, `sort_order`)
VALUES (0, 1, 'route', 'information/contact', 'kontakty', 0);
You can edit these records manually in "Design → SEO URL" (Design → SEO URL). For products, categories, manufacturers, and information pages, it is more convenient to fill them in on the "SEO" tab of the entity's form.

How does a request reach the startup/seo_url controller?
The web server passes PHP not the "pretty" address, but with the index.php parameter. The distribution includes a file for this purpose: _route_. It needs to be renamed to .htaccess.txt, and then the mod_rewrite rule will convert .htaccess into /. Under Nginx, the same must be described manually:index.php?_route_=noutbuky/
location / {
try_files $uri $uri/ @opencart;
}
location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
Next, the request passes through the core (this path is described in detail in the article on framework.php and the request path). Before the main controller runs, the startup pre-actions are executed, and is among them. Its task is to fill startup/seo_url as if the user had opened a regular $this. After that, the standard routing by the route= parameter takes over.index.php?route=…&product_id=…
flowchart TD
A["Browser: /noutbuky/macbook-pro"] --> B["Server: index.php?_route_=..."]
B --> C["startup/seo_url: index()"]
C --> D["Lookup of each segment in seo_url"]
D --> E["Filling request->get"]
E --> F["Router calls the controller from route"]
F --> G["$this->url->link() in templates"]
G --> H["rewrite(): parameters are converted to SEO URLs"]
The switch is turned on in "System → Settings" (System → Settings), on the "Server" tab (Server), in the option for using SEO URLs. There is an important difference between versions. OpenCart 3.0: parsing config_seo_url always runs, and the setting only affects whether _route_ is connected to link generation. OpenCart 4.1: parsing and rewrite are both inside the rewrite() check, so with the option disabled, "pretty" addresses are not recognized at all.config_seo_url

How OpenCart 3.0 parses the address
In 3.0, the string is split by slashes, and the empty last segment (the trailing _route_) is discarded. Then a separate SQL query is executed for each segment:/
catalog/ · OpenCart 3.0.5.1 · lines 18–34
foreach ($parts as $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} else {
$this->request->get['path'] .= '_' . $url[1];
}
}
Several non-obvious things follow from this code:
- The language is not taken into account during parsing. The filter applies only by
andkeyword. If the Ukrainian and English versions have the same keyword, the first row found is used. For a product this is not a problem, becausestore_idis the same, but the page language will not switch as a result.product_id - Categories are concatenated into
. The addresspathis converted into/noutbuky/apple. The order of segments in it matters.path=20_27 - An unknown segment immediately produces a 404:
· OpenCart 3.0.5.1 · lines 44–51catalog/
if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
$this->request->get['route'] = $query->row['query'];
}
} else {
$this->request->get['route'] = 'error/not_found';
break;
}
The first line of this fragment explains how route addresses work in 3.0: if does not contain one of the four known parameters, the entire value becomes query. So the route, query = 'information/ row will open the contacts page at the address keyword = 'kontakty'. But the /kontakty row will break, because blog_id=5 becomes equal to route. When no blog_id=5 is set, the controller substitutes it itself based on the parameter found: route, product/product, product/category, or product/.information/
What changed in OpenCart 4.1?
In 4.1, the controller became universal. It no longer knows about products and categories; it simply converts each found row into a "key = value" pair in GET:
catalog/ · OpenCart 4.1.0.4 · lines 35–51
foreach ($parts as $key => $value) {
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($value);
if ($seo_url_info) {
$this->request->get[$seo_url_info['key']] = html_entity_decode($seo_url_info['value'], ENT_QUOTES, 'UTF-8');
unset($parts[$key]);
}
}
if (!isset($this->request->get['route'])) {
$this->request->get['route'] = $this->config->get('action_default');
}
if ($parts) {
$this->request->get['route'] = $this->config->get('action_error');
}
What matters here for the developer:
- The SQL has been moved into the
model, methodcatalog/model/ design/ seo_url.php . Overriding the behavior is now more convenient through events on the model rather than by editing the controller. For more about models, see the article about models and $this->db.getSeoUrlByKeyword() - The key can be anything:
,route,product_id,path, or a parameter of your module. Therefore, custom SEO URLs in 4.1 are added without any core modifications.language - The loop does not stop at the first unknown segment. It goes through all of them, and then, if anything remains unrecognized, sets
. The effect is the same (404), but third-party code that cleans upaction_errorworks more predictably in this scheme.$parts - Without
,routeis substituted from the core config (usually the home page). The article about config.php and system/config explains where such values come from.action_default
Look at categories separately. In 4.1, is stored as a regular value, without concatenation. If the address contains two categoryA section of the catalog that contains products. It may have subcategories. More in the glossary → segments, the second will simply overwrite the first. Therefore, the row for a nested category must contain the full path in path (for example value).20_27
How links are converted into SEO URLs: the rewrite() method
You do not form SEO addresses manually. Controllers call , and the URL class ($this) passes the result through all registered rewrite objects. system/ adds itself there by calling startup/seo_url, so its $this method receives the finished link with the query string.rewrite($link)
OpenCart 3.0: a whitelist of parameters
Rewrite in 3.0 handles only (for product_id), product/product, manufacturer_id, and information_id. Unlike parsing, here there is a filter by path, so links are generated in the language of the current page. There is a trap associated with language_id: if even one category in the chain has no keyword, the accumulated path is reset along with the segments added earlier, and $url is still discarded from the parameters. The method returns the original link with path only when no other parameter then yields a keyword. Otherwise, you get an SEO URL without category segments, for example only the product keyword, if index.php?route=… appears in the link after product_id. The path parameter is not rewritten at all, so even with the route row in the table, the contacts link will remain "ugly", although the address information/contact will still open./kontakty
OpenCart 4.1: each pair is looked up in the table
catalog/ · OpenCart 4.1.0.4 · lines 116–126
$index = $key . '=' . $value;
if (!isset($this->data[$language_id][$index])) {
$this->data[$language_id][$index] = $this->model_design_seo_url->getSeoUrlByKeyValue((string)$key, (string)$value);
}
if ($this->data[$language_id][$index]) {
$paths[] = $this->data[$language_id][$index];
unset($query[$key]);
}
Each pair from the query string is looked up through , and the result is cached in the getSeoUrlByKeyValue() property within a single request. This matters because on a category page, dozens of links share the same $data and route=…. The found segments are sorted by language=…, and whatever is missing from the table remains in the query string. This gives the diagnostic rule: if you see sort_order in 4.1, the table lacks a row for the pair / / route in the current language and store.product/product
How to add an SEO URL for your own module
A typical task looks like this: a blog module has an article page with a route and its own parameter, and it needs to be served at a human-readable address.
OpenCart 4.1
- When installing the module, add a row for the route:
,key = 'route'= the full route of your controller (in 4.1 this is the path withvalue),extension/….keyword = 'blog' - When saving an article in the admin, write a row
,key = 'article_id'for each language and each store.value = '5' - Set
so that the route comes before the article. Then the address will look likesort_order./blog/moya-stattia - When deleting an article or uninstalling the module, remove your rows so that "orphans" do not accumulate in the table.
// Приклад: збереження SEO-ключів статті в адмін-моделі модуля (4.1)
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
foreach ($data['article_seo_url'] as $store_id => $languages) {
foreach ($languages as $language_id => $keyword) {
if ($keyword) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'article_id', `value` = '" . (int)$article_id . "', `keyword` = '" . $this->db->escape($keyword) . "', `sort_order` = '1'");
}
}
}
Nothing needs to be changed either in or in the page controller (how the controller is structured): it will receive startup/seo_url in article_id, as if it came as a regular GET parameter.$this
OpenCart 3.0
The standard mechanism is not enough here. Parsing will turn into a broken article_id=5, and rewrite will ignore your parameter. There are two working approaches. The first: an OCMOD modification of route that adds your key to the parsing branches and to the catalog/ whitelist. The second: a custom startup controller that registers another rewrite object through rewrite() and parses its own segments. Keywords in the table must be unique within a store. Otherwise, due to the absence of a language filter during parsing, you will get unpredictable results.$this
Why does an SEO URL return 404 or not get generated: diagnostics
Most SEO URL problems come down to a few causes. Check them in this order:
- Does
arrive? Temporarily output_route_in the controller. If there is no$this->request ->get there, the problem is at the server level: the file_route_was not renamed,.htaccessis disabled, the rule is missing in Nginx, or it was installed in a subdirectory without editingAllowOverride.RewriteBase - Is
enabled? In 4.1, without it, parsing does not happen at all.config_seo_url - Do
andstore_idmatch? After adding a language or a second store, old products have no rows for the new combinations. Links for them are generated without SEO URLs.language_id - Are all categories in the chain filled in? In 3.0, one category without a keyword "breaks" the path for all of its descendants.
- Are there no duplicates? The same keyword for two entities in one store produces a random parsing result: "the wrong product opens".

Filling in missing keywords in bulk after a catalog import is inconvenient by hand. There are generators of transliterated SEO URLs for this, for example SEO URL Generator PRO, but you can also do the same with your own script based on the table scheme described above. Language prefixes and hreflangA hint to search engines about the language versions of a page. More in the glossary → on top of this mechanism are covered in a separate article about multilingual support and URL prefixes.
If your store runs on OpenCart 3.0 and you would rather not maintain your own modifications, we recommend our module OCT SEO PRO. It brings SEO URLs, redirects, and the sitemap together in one place. Keywords, redirects from old addresses after they change, and the site map are conveniently configured from the admin, and you do not have to edit the startup/seo_url table by hand.seo_url
Summary
- The
table links a keyword to a query parameter. In 3.0 this is theseo_urlfield; in 4.1 it is thequery/keypair plusvalue.sort_order works in both directions:startup/seo_urlparsesindex()into GET parameters, and_route_converts links withrewrite()into SEO URLs.$this->url ->link() - OpenCart 3.0 knows only four entity types and does not filter by language during parsing. Custom pages will require a modification or your own rewrite.
- OpenCart 4.1 is universal: for a module to receive an SEO URL, correct rows in the table are enough.
- A
tail or a 404 almost always means a missing row for a specific store/language pair or a problem with the server rule.?route=…
Next, it is worth looking at what happens after the address is parsed: how the router finds the controller by route= and how admin and catalog work on one core (the admin does not use SEO URLs). The remaining topics about controllers, models, and templates are collected in the section MVC-L: controllers, models, templates.