Remove index.php?route=common/home from OpenCart

To simply remove that, you can do a basic replace in /catalog/controller/common/seo_url.php

Find:

return $link;

Before it on a new line put:

$link = str_replace('index.php?route=common/home', '', $link);

Edit by TheBlackBenzKid: If you want full SEO just use this line instead of the above:

$link = str_replace('index.php?route=', '', $link);

Also make sure SEO URLs is turned on in the Admin panel of the store.


I really like Victor Schröder's solution above for it's simplicity. Thanks! I created a vQmod based on his code mods in case it would be helpful to anyone. here is the code:

<modification>

    <file name="system/library/url.php">
        <operation>
            <search position="before"><![CDATA[$url .= 'index.php?route=' . $route;]]></search>
            <add><![CDATA[
                if ('common/home' == $route) {
                    if ($args) {
                        $url .= '?' . str_replace('&', '&amp;', '&' . ltrim($args, '&'));
                    }
                } else {
            ]]></add>
        </operation>
        <operation>
            <search position="before"><![CDATA[foreach ($this->rewrite as $rewrite) {]]></search>
            <add><![CDATA[
                }
            ]]></add>
        </operation>
    </file>

    <file name="catalog/controller/common/seo_url.php">
        <operation>
            <search position="replace"><![CDATA[parse_str($url_info['query'], $data);]]></search>
            <add><![CDATA[
                if (isset($url_info['query'])) parse_str($url_info['query'], $data);
            ]]></add>
        </operation>
    </file>

</modification>

The previous "solutions" are wrong because they are attacking the SEO URL translate. What you want is to deal with the URL generation inside OpenCart.

Let's keep it simple. Go to /system/library/url.php and look at the public function link. Replace the function with this version:

public function link($route, $args = '', $connection = 'NONSSL') {
    if ('NONSSL' == $connection) {
        $url = $this->url;
    } else {
        $url = $this->ssl;  
    }

    if ('common/home' == $route) {
        if ($args) {
            $url .= '?' . str_replace('&', '&amp;', '&' . ltrim($args, '&')); 
        }
    } else {
        $url .= 'index.php?route=' . $route;
        if ($args) {
            $url .= str_replace('&', '&amp;', '&' . ltrim($args, '&')); 
        }
    }

    foreach ($this->rewrite as $rewrite) {
        $url = $rewrite->rewrite($url);
    }

    return $url;
}

Simple like that. I can't belive why this is not in OpenCart's core.

EDIT:

I run some tests and if the SEO URLs are enabled, it becomes necessary to make one single edit in the /catalog/controller/common/seo_url.php to avoid an "Undefined index" error.

Inside public function rewrite, replace this line:

parse_str($url_info['query'], $data);

With this one:

if (isset($url_info['query'])) parse_str($url_info['query'], $data);

Now it really works.