Alex Rivera | Logout

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

Asked 2012-05-30T09:47:29.387
26

I currently have User SEO URL's set to Yes in OpenCart Admin.

System -> Settings -> Store -> Server -> User SEO URL's

So far, all tags and SEO links are working; the command has done the desired effect.

However for the homepage and a few other links; how do I remove:

index.php?route=common/home

From the URL? Do I have to literally do a find and replace in the hardcode PHP files and risk upgrades or is there another way?

(without bloating performance i.e no poor amateur tools such as vQmod)

Edit
Report

2 Answers

8

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('&', '&', '&' . ltrim($args, '&')); 
        }
    } else {
        $url .= 'index.php?route=' . $route;
        if ($args) {
            $url .= str_replace('&', '&', '&' . 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.

answered 2013-03-09T01:40:22.253
2

How about replacing a link in logo with <?php echo $base; ?>. It will make a link to base domain and will remove index.php?route=common/home.

answered 2012-08-14T09:13:28.337

Your Answer