How to Remove Common/Home in OpenCart 2.3.x and 3.x

So, you’ve enabled your SEO URLs in OpenCart.

Everything is looking fine and you’re happy about the new, shorter URLs.

However, there’s this one, last annoying URL that keeps bugging you.

The index.php?route=common/home appearing after you click your home page logo.

We believe it’s time to solve that once and for all.

In this tutorial, we’ll show you how to get rid of that in two ways - the quick and easy way, as well as the clean and correct way.

Let’s get this over with.

The Problem

This is how the default URL looks like when you’re at the home:
 


 

However, when you click on your logo, this happens:
 


Quite unpleasant.

And it has the audacity to appear even after you’ve successfully enabled your SEO URLs.

Even with the new OpenCart 3.0 update, there’s still no way to edit this from the admin panel.

This is why, we must resort to alternative methods.

The Solutions

There are 2 main methods to remove this from your store’s URL.

  1. Modify your .htaccess file.

  2. Use the OpenCart Events system.

Method #1

To modify your htaccess file, you need to open your OpenCart root directory (with FileZilla for example).

If your SEO URLs are enabled successfully, your htaccess file should already be renamed from .htaccess.txt to just .htaccess.

Edit/View the htaccess file and find this line:

RewriteBase /

Below it, paste these three lines:

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^index\.php$ http://%{HTTP_HOST}? [R=301,L]

Save your htaccess file and your store logo should now be generating the clean URL of your home page.

Method #2


IMPORTANT: This will work only for OpenCart 2.3.0.0+ and 3.0+.

For older OpenCart versions, use Method #1.


Step 1:

Upload a new file in your OpenCart store:

catalog/controller/extension/common/seo_url_common_home.php

It must contain the following code:

<?php

class ControllerExtensionCommonSeoUrlCommonHome extends Controller {
    public function index() {
        if ($this->config->get('config_seo_url') && !$this->config->get('seo_url_common_home_status')) {
            $this->url->addRewrite($this);
            $this->config->set('seo_url_common_home_status', 1);
        }
    }

    public function rewrite($link) {
        $url = '';
        $data = array();
        $url_info = parse_url(str_replace('&amp;', '&', $link));

        if (empty($url_info['query'])) {
            return $link;
        }

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

        if (isset($data['route']) && $data['route'] == 'common/home') {
            $is_common_home = true;
        } else {
            $is_common_home = false;
        }

        if ($is_common_home) {
            unset($data['route']);

            $query = '';

            if ($data) {
                foreach ($data as $key => $value) {
                    $query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
                }

                if ($query) {
                    $query = '?' . str_replace('&', '&amp;', trim($query, '&'));
                }
            }

            return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
        } else {
            return $link;
        }
    }
}

Step 2:

In your database run the following queries:

IMPORTANT: Before running the queries, replace {PREFIX} with your OpenCart prefix.

Typically it is oc_, but you might have changed it with another value. To see your OpenCart prefix, open up the OpenCart file /config.php and find the line saying define('DB_PREFIX', '...');

DELETE FROM `{PREFIX}event` WHERE code='seo_url_common_home';

INSERT INTO `{PREFIX}event` (`code`, `trigger`, `action`, `status`) VALUES ('seo_url_common_home', 'catalog/*/before', 'extension/common/seo_url_common_home', 1);

Step 3:

Make sure System > Settings > Edit > tab Server > Use SEO URLs is set to Yes.

Method #2 works for both Apache and NGINX servers, while Method #1 works only on Apache servers.

That's all!

Now all URLs containing route=common/home will be rewritten to not contain it.

Conclusion

This puts an end to the common/home situation in OpenCart. You should no longer experience the issue and keep your home page URL clean.

Join 11,000+ subscribers receiving actionable E-commerce advice

* Unsubscribe any time
comments powered by Disqus