SEO URLs
By default addresses look like index.php?route=product/product&product_id=42. A SEO URL is a short readable address of the same page, for example /en-gb/ceramic-mug. It is easier to read for people and search engines. The page itself and its controller do not change — only the address.
Turning it on
Three steps are needed.
- In the admin panel:
System → Settings, edit the store, theServertab, turn on «Use SEO URLs». - Teach the web server to pass unknown addresses to
index.php. - Give keywords to products, categories and pages.
Web server rules
On Apache the rules are already in the distribution — rename the file in the site root:
mv .htaccess.txt .htaccessOn Nginx add the rules to the site configuration:
location / {
try_files $uri $uri/ @opencart;
}
location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}An address that is not a real file is handed to OpenCart in the _route_ parameter, and the engine finds the page by the keywords.
Keywords of products
Open a product in Catalog → Products, the SEO tab, and enter a keyword for each store and language: ceramic-mug. The same tab exists for categories, manufacturers and information pages.
Open the storefront — links to the product now lead to the short address, and the old address with product_id=42 still works.
Where keywords are stored
All keywords are in the table oc_seo_url. Each row links a keyword with a pair «key and value»:
key | value | keyword |
|---|---|---|
product_id | 42 | ceramic-mug |
path | 20 | desktops |
route | information/hello | hello |
The whole list is shown in Design → SEO URL.
A keyword for your own page
In Design → SEO URL add a row: the key route, the value — the route of your controller, for example information/hello, the keyword hello, your store and language.
The page opens at an address like http://shop.test/en-gb/hello. How exactly the parts of the address are assembled — with the language at the start or without it — depends on the release.
Links in code
Nothing changes in code. $this->url->link() returns the short address by itself when SEO URLs are on and a keyword exists:
$href = $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=42');$href contains the short address of the product, and for a product without a keyword — the usual long one.
Common mistake
A link is written by hand in a template: <a href="index.php?route=product/product&product_id=42">. It works, but stays long, and search engines see two addresses of one page. Build every link in the controller with $this->url->link() and pass it to the template as a variable.