Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It turns out this can be done with a relatively simple change to a single file. No .htaccess rewrite rules, simply patch the catalog/controller/common/seo_url.php file and add your pretty URLs to an existing database table.</p> <hr> <p><strong>The patch to seo_url.php:</strong></p> <pre><code>Index: catalog/controller/common/seo_url.php =================================================================== --- catalog/controller/common/seo_url.php (old) +++ catalog/controller/common/seo_url.php (new) @@ -48,7 +42,12 @@ $this-&gt;request-&gt;get['route'] = 'product/manufacturer/product'; } elseif (isset($this-&gt;request-&gt;get['information_id'])) { $this-&gt;request-&gt;get['route'] = 'information/information'; - } + } else { + $query = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this-&gt;db-&gt;escape($this-&gt;request-&gt;get['_route_']) . "'"); + if ($query-&gt;num_rows) { + $this-&gt;request-&gt;get['route'] = $query-&gt;row['query']; + } + } if (isset($this-&gt;request-&gt;get['route'])) { return $this-&gt;forward($this-&gt;request-&gt;get['route']); @@ -88,7 +87,15 @@ } unset($data[$key]); - } + } else { + $query = $this-&gt;db-&gt;query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this-&gt;db-&gt;escape($data['route']) . "'"); + + if ($query-&gt;num_rows) { + $url .= '/' . $query-&gt;row['keyword']; + + unset($data[$key]); + } + } } } </code></pre> <p>There are two edits required. The first extends the <code>index()</code> function to look in the <code>url_alias</code> table for <em>any</em> keyword matching <code>$this-&gt;request-&gt;get['_route_']</code>.</p> <p>The second extends the <code>rewrite()</code> function to look in the <code>url_alias</code> table for <em>all</em> routes, not just those for products, manufacturers, and information pages.</p> <hr> <p><strong>Adding entries to the database:</strong></p> <pre><code>INSERT INTO `url_alias` (`url_alias_id`, `query`, `keyword`) VALUES (NULL, 'checkout/cart', 'cart'); </code></pre> <hr> <p>That's it. <a href="http://example.com/cart">http://example.com/cart</a> should return the same thing that <a href="http://example.com/index.php?route=checkout/cart">http://example.com/index.php?route=checkout/cart</a> does, and OpenCart should recognize <code>$this-&gt;url-&gt;link('checkout/cart');</code> and return a link to the pretty URL <a href="http://example.com/cart">http://example.com/cart</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload