Post by Condor45 » Tue Feb 14, 2023 4:17 am

I’ve recently rebuilt my OC3.X site in OC4.0.1.1.

I’ve had my site running for years and it’s well indexed with many pages, and have more sites to move over from 3 to 4.

Everything has gone fine except for the language in the URL. I’ve searched on here and searched on Google but to no avail.

Example:
https://www.domain.com/en-gb/product/ca ... roduct-url

This is a single language site.

Adding the en-gb means my urls change which is a logistical nightmare for historical marketing.

Am I missing something really obvious in the admin, or is adding the language to the url really a core feature of OC4?

Newbie

Posts

Joined
Tue Feb 14, 2023 4:10 am

Post by Johnathan » Tue Feb 14, 2023 10:22 pm

It's a core feature, unfortunately. I agree that it makes no sense for a single language site, but I haven't had time to look into it at this point.

I just went through the code and I'm not entirely sure this will work, but try the following and see how it goes:

------------------------------------------------------------------------------
IN:
/system/library/url.php

BEFORE:
foreach ($this->rewrite as $rewrite) {

WITH:
$url = str_replace('language=en-gb', '', $url);
$url = str_replace('&&', '&', $url);
------------------------------------------------------------------------------

That's the simplest edit I could come up with, but if it doesn't work let me know and I'll see if I can find an alternate method.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Condor45 » Wed Feb 15, 2023 12:21 am

Johnathan, thanks for taking the time to reply.
I read a thread on Git after I posted this where Daniel confirmed it's a core feature.
It makes upgrading to 4 off-putting, and even new single-lang sites shouldn't have this URL structure.
Your suggestion does strip the en-gb from the URL, and both versions load correctly. The canonical still displays en-gb, so there's a few places to look at.
We'll spend more time on this later in the week and I'll post the results in here, as I can see a few people have asked the question on various sites.
Thanks again.

Newbie

Posts

Joined
Tue Feb 14, 2023 4:10 am

Post by tdaubs » Thu Feb 16, 2023 6:53 am

Personally, I feel like v4 needs more time in the kitchen before using it on a production site. Why did you want to move from 3 to 4?

Image
Opencart Support . Opencart Galaxy . Buy Me a Coffee?


User avatar
Active Member

Posts

Joined
Fri Apr 08, 2011 4:51 am
Location - Southern California

Post by jamesalex » Fri Feb 17, 2023 1:12 am

I'm trying to apply your fix for the /en-gb issue in 4.0.1.1 but it doesn't seem to be working for me. I'm suspecting I'm not reading your instructions properly.

I'm editing url.php as instructed and putting the 2 new lines before the foreach command but it throws up a ton of errors, all saying:

Warning: Undefined array key 1 in /home/yourwebsite/public_html/catalog/controller/startup/seo_url.php on line 61

Code: Select all

public function link(string $route, string|array $args = '', bool $js = false): string {
		$url = $this->url . 'index.php?route=' . $route;

		if ($args) {
			if (is_array($args)) {
				$url .= '&' . http_build_query($args);
			} else {
				$url .= '&' . trim($args, '&');
			}
		}
    // the two new lines here, before the foreach, the second line is line 61
    $url = str_replace('language=en-gb', '', $url);
    $url = str_replace('&&', '&', $url);
    
		foreach ($this->rewrite as $rewrite) {
			$url = $rewrite->rewrite($url);
		}

		if (!$js) {
			return str_replace('&', '&', $url);
		} else {
			return $url;
		}
	}

New member

Posts

Joined
Thu Apr 19, 2012 9:03 pm

Post by Johnathan » Fri Feb 17, 2023 1:44 am

I didn't test it, so it seems like it's probably not a good solution. Eventually I'll look for a better solution for this, but I don't have time to run a bunch of tests at the moment. If anyone else figures it out, feel free to post the solution here.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by dimtsef » Mon Jan 29, 2024 10:31 pm

well i tried and i have the same error showing, the million dollar question is does this fix works ok even with the error ? i can always hide this error , but will affect the operation of the urls and seo negative ? or once its done it stays like this. Also in a feature upgrade i guess i have to re insert this code to hide the UGLY language code showing in my urls ??

Newbie

Posts

Joined
Mon Nov 07, 2022 4:09 am

Post by dimtsef » Mon Jan 29, 2024 10:43 pm

well that was fast, i found the solutions as described here, for me worked 100% !

https://webocreation.com/how-to-remove- ... #gsc.tab=0

Newbie

Posts

Joined
Mon Nov 07, 2022 4:09 am

Post by OSWorX » Sat Feb 17, 2024 8:39 pm

Just for completeness, there was also an entry at Github (but finally refused):
https://github.com/opencart/opencart/pu ... be97d19870

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 4 guests