No results found

Try a different search query

Popular searches:

Add to Cart

Cart

You have no purchases yet

Browse Marketplace

Redirect from disabled language version (en > uk) in OpenCart

A common SEO and usability problem in online stores based on OpenCart, when there is a need to disable or remove the English (or any other) language version of the site.

2 min read
40
2
Redirect from disabled language version (en > uk) in OpenCart

A common SEO and usability problem in OpenCart-based online stores when there is a need to disable or remove the English (or any other) language version of the site. Usually, after disabling a language in the admin panel, all old URLs that have already been indexed by search engines (for example, Google) start returning a 404 error (Page not found). This negatively affects user behavior factors and reduces the site's position in search results.

 

If your site used a clear language prefix in links (for example, redirecting from /en/ to the homepage or to old Russian pages like /ru/), and the URL structure (SEO URL) is identical in this case — such a task can and should be solved at the server level through the .htaccess file

 

# Redirect from /en/ or /en to the homepage
RewriteCond %{REQUEST_URI} ^/en/?$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/en/(.*)$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/ [R=301,L]

 

Your case, if the links on the site went without a language prefix, and SeoPro is enabled in the store settings

The modifier automatically intercepts requests to the disabled language version and implements a correct 301 redirect (Moved Permanently) to the base (Ukrainian) localization of the site with full preservation of the URL structure (if the page exists).

In the current code of the modifier, language ID 2 is set by default, which corresponds to Ukrainian localization on the test and most standard sites.

 

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>EN redir to UKR</name>
    <code>EN redir to UKR</code>
    <version>1.0</version>
    <author>kJlukOo</author>
    <link>https://cleanphp.pp.ua</link>
<file path="system/library/seopro.php">
    <operation>
        <search><![CDATA[public function prepareRoute($parts) {]]></search>
        <add position="before"><![CDATA[
            function enRedirToUkr($keyword)
            {
                $query_string = $this->getQueryByKeyword($keyword, 2);
                if ($query_string) {


                    $url_data = explode('=', $query_string);
                    
                    if (count($url_data) == 2) {
                        $route_type = $url_data[0]; // 'information_id', 'product_id' и т.д.
                        $route_id   = $url_data[1];
                        
                        $route = '';
                        if ($route_type == 'product_id') {
                            $route = 'product/product';
                        } elseif ($route_type == 'category_id') {
                            $route = 'product/category';
                        } elseif ($route_type == 'manufacturer_id') {
                            $route = 'product/manufacturer/info';
                        } elseif ($route_type == 'information_id') {
                            $route = 'information/information';
                        }
                        
                        if ($route) {
                            $new_url = $this->url->link($route, $route_type . '=' . (int)$route_id);
                            $this->response->redirect($new_url, 301);
                        }
                    }
                }
            }
        ]]></add>
    </operation>
</file>
<file path="system/library/seopro.php">
    <operation>
        <search><![CDATA[$query = $this->getQueryByKeyword($parts[$id]);]]></search>
        <add position="after"><![CDATA[
            if(!$query) 
                    $this->enRedirToUkr($parts[$id]);
        ]]></add>
    </operation>
</file>
</modification>
kJlukOo

kJlukOo

article
1
views
40
likes
2
followers
0

Related Posts

Comments (0)

Replying to

Please log in to leave a comment

Log In

No comments yet

Be the first to comment on this article!

We use cookies

We use cookies and similar technologies to improve your experience, analyse traffic, and show personalised ads. Read our Cookie Policy for details.