Please note that these changes were applied to v0.7.7.
I have been searching through the forums to see how to get URL aliases/SEO friendly URLs to work. I got some hints, but no step-by-step how-to. I've finally gotten SEO friendly URLs to work on my setup and would like to share what I did.
There is no requirement for the URL alias feature to be enabled.
I was unable to see how OpenCart could convert pretty URLs into something OpenCart could understand, so I added this code (four new lines) to library/application/router.php.
Code: Select all
if (isset($this->routes[$path[0]])) { /* existing code */
/* ... existing code ... */
} /* existing code */
else if(isset($path[1])) { /* new code */
for ($i = 0; $i < sizeof($path); $i += 2) /* new code */
$request->set($path[$i], isset($path[$i+1]) ? $path[$i+1] : NULL); /* new code */
} /* new code */
Next some work needs to be done in library/environment/url.php.
Rename the last function in the file from 'create' to 'create_ugly' and add the following replacement function wherever you wish (in url.php).
Code: Select all
function create($server, $controller, $action = NULL, $query = array()) {
if(strpos($server, "/admin/") > 0) {
return $this->create_ugly($server, $controller, $action, $query);
}
$link = 'controller/' . $controller;
if ($action) {
$link .= '/action/' . $action;
}
foreach ($query as $key => $value) {
if ($value) {
$link .= '/' . $key . '/' . urlencode($value);
}
}
if (isset($this->data[$link])) {
$link = $this->data[$link];
} else {
$link = 'index.php/' . $link;
}
return $server . $link;
}
URLs in the catalog should now be SEO friendly, but administration URLs will be unchanged.
That's it.
Though it isn't open for business, this is the site I'm bringing up (with the modifications described in this post).
http://www.eeegads.com