{"id":2868,"date":"2014-03-01T11:36:25","date_gmt":"2014-03-01T11:36:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/01\/remove-index-phproutecommon-home-from-opencart-collection-of-common-programming-errors\/"},"modified":"2014-03-01T11:36:25","modified_gmt":"2014-03-01T11:36:25","slug":"remove-index-phproutecommon-home-from-opencart-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/01\/remove-index-phproutecommon-home-from-opencart-collection-of-common-programming-errors\/","title":{"rendered":"Remove index.php?route=common\/home from OpenCart-Collection of common programming errors"},"content":{"rendered":"<p>So, I&#8217;m using 1.5.5.1 and no one answer on this question solved my problem. However, combining the answers from @Jay Gilford, @TheBlackBenzKid and @rkaartikeyen I came up with a fully working solution.<\/p>\n<p>Remember to enable seo urls as shown by @TheBlackBenzKid.<\/p>\n<p>An explanation can be found below the code.<\/p>\n<pre>\n[php]\nclass ControllerCommonSeoUrl extends Controller {\n    public function index() {\n        \/\/ Add rewrite to url class\n        if ($this-&gt;config-&gt;get('config_seo_url')) {\n            $this-&gt;url-&gt;addRewrite($this);\n        }\n\n        \/\/ Decode URL\n        if (isset($this-&gt;request-&gt;get['_route_'])) {\n            $parts = explode('\/', $this-&gt;request-&gt;get['_route_']);\n\n            foreach ($parts as $part) {\n                $query = $this-&gt;db-&gt;query(\"SELECT * FROM \" . DB_PREFIX . \"url_alias WHERE keyword = '\" . $this-&gt;db-&gt;escape($part) . \"'\");\n\n                if ($query-&gt;num_rows) {\n                    $url = explode('=', $query-&gt;row['query']);\n\n                    if ($url[0] == 'product_id') {\n                        $this-&gt;request-&gt;get['product_id'] = $url[1];\n                    }\n\n                    if ($url[0] == 'category_id') {\n                        if (!isset($this-&gt;request-&gt;get['path'])) {\n                            $this-&gt;request-&gt;get['path'] = $url[1];\n                        } else {\n                            $this-&gt;request-&gt;get['path'] .= '_' . $url[1];\n                        }\n                    }   \n\n                    if ($url[0] == 'manufacturer_id') {\n                        $this-&gt;request-&gt;get['manufacturer_id'] = $url[1];\n                    }\n\n                    if ($url[0] == 'information_id') {\n                        $this-&gt;request-&gt;get['information_id'] = $url[1];\n                    }   \n                } else {\n                    $this-&gt;request-&gt;get['route'] = 'error\/not_found';   \n                }\n            }\n\n            if (isset($this-&gt;request-&gt;get['product_id'])) {\n                $this-&gt;request-&gt;get['route'] = 'product\/product';\n            } elseif (isset($this-&gt;request-&gt;get['path'])) {\n                $this-&gt;request-&gt;get['route'] = 'product\/category';\n            } elseif (isset($this-&gt;request-&gt;get['manufacturer_id'])) {\n                $this-&gt;request-&gt;get['route'] = 'product\/manufacturer\/info';\n            } elseif (isset($this-&gt;request-&gt;get['information_id'])) {\n                $this-&gt;request-&gt;get['route'] = 'information\/information';\n            }else {\n                $this-&gt;request-&gt;get['route'] = $this-&gt;request-&gt;get['_route_'];\n            }\n\n            if (isset($this-&gt;request-&gt;get['route'])) {\n                return $this-&gt;forward($this-&gt;request-&gt;get['route']);\n            }\n        }\n    }\n\n    public function rewrite($link) {\n        $url_info = parse_url(str_replace('&amp;', '&amp;', $link));\n\n        $url = ''; \n\n        $data = array();\n\n        parse_str($url_info['query'], $data);\n\n        foreach ($data as $key =&gt; $value) {\n            if (isset($data['route'])) {\n                if (($data['route'] == 'product\/product' &amp;&amp; $key == 'product_id') || (($data['route'] == 'product\/manufacturer\/info' || $data['route'] == 'product\/product') &amp;&amp; $key == 'manufacturer_id') || ($data['route'] == 'information\/information' &amp;&amp; $key == 'information_id')) {\n                    $query = $this-&gt;db-&gt;query(\"SELECT * FROM \" . DB_PREFIX . \"url_alias WHERE `query` = '\" . $this-&gt;db-&gt;escape($key . '=' . (int)$value) . \"'\");\n\n                    if ($query-&gt;num_rows) {\n                        $url .= '\/' . $query-&gt;row['keyword'];\n\n                        unset($data[$key]);\n                    }                   \n                } elseif ($key == 'path') {\n                    $categories = explode('_', $value);\n\n                    foreach ($categories as $category) {\n                        $query = $this-&gt;db-&gt;query(\"SELECT * FROM \" . DB_PREFIX . \"url_alias WHERE `query` = 'category_id=\" . (int)$category . \"'\");\n\n                        if ($query-&gt;num_rows) {\n                            $url .= '\/' . $query-&gt;row['keyword'];\n                        }                           \n                    }\n\n                    unset($data[$key]);\n                }\n            }\n        }\n\n        if ($url) {\n            unset($data['route']);\n\n            $query = '';\n\n            if ($data) {\n                foreach ($data as $key =&gt; $value) {\n                    $query .= '&amp;' . $key . '=' . $value;\n                }\n\n                if ($query) {\n                    $query = '?' . trim($query, '&amp;');\n                }\n            }\n\n            return $url_info['scheme'] . ':\/\/' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('\/index.php', '', $url_info['path']) . $url . $query;\n        } else {\n            $link = str_replace('index.php?route=', '', $link);\n            return $link;\n        }\n    }   \n}\n<\/pre>\n<p>Apparently, @Jay Gilford and @TheBlackBenzKid solve the issue of the urls being properly written on the page.<\/p>\n<pre>\nLine 113\n\n$link = str_replace('index.php?route=', '', $link);\n<\/pre>\n<p>But it seems to break the urls since the Controller can&#8217;t find the pages and therefore reverts to the error page.<\/p>\n<pre>\nLine 38 - 40\n\n} else {\n    $this-&gt;request-&gt;get['route'] = 'error\/not_found';   \n}\n<\/pre>\n<p>@rkaartikeyen&#8217;s solution solves this problem by setting the current route to the requested route<\/p>\n<pre>\nLine 51 - 53\n\nelse {\n    $this-&gt;request-&gt;get['route'] = $this-&gt;request-&gt;get['_route_'];\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So, I&#8217;m using 1.5.5.1 and no one answer on this question solved my problem. However, combining the answers from @Jay Gilford, @TheBlackBenzKid and @rkaartikeyen I came up with a fully working solution. Remember to enable seo urls as shown by @TheBlackBenzKid. An explanation can be found below the code. [php] class ControllerCommonSeoUrl extends Controller { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2868","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2868"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2868\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}