Post by jamesalex » Thu Feb 16, 2023 9:55 pm

I've noticed with opencart 4 it's now adding /en-gb/catalog/ to the url.
I can't have this on my clients site as I'm upgrading from opencart 2 and they have spent a ton of time and money on SEO. So ideally I need to remove these 2 directories from the displayed url and also I need the site to work without them.

Plus 'catalog' is US spelling and my client is in the UK (spelled catalogue)

It's not a multi-language site so entering the address without /en-gb does work but I can't get it removed from the displayed url. I've gone through a load of solutions on stackoverflow as well as here, nothing has really worked.

I know I need to create a RewriteRule in the .htaccess but nothing i've found seems to work.

Does anyone have a definitive solution for this?

I'm guessing it needs to do 2 things:

1. make sure https://www.website.com/categories works as it did with opencart 2
2. remove /en-gb/catalog from the displayed url.

Below is my generated .htacess so far:

## SEO URL Settings
RewriteEngine On
## If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
## Rewrite Rules
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|webp|js|css|svg)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

RewriteCond %{REQUEST_URI} !(.*)en-gb
RewriteRule ^en-gb/(.*)$ /$1 [L,NC,R=301]
RewriteRule ^catalog/(.*)$ /$1 [L,NC,R=301]

New member

Posts

Joined
Thu Apr 19, 2012 9:03 pm

Post by by mona » Thu Feb 16, 2023 10:02 pm

same question from yesterday
viewtopic.php?t=230727

other related answers that can be found on google
OC4 is not really ready for production sites as yet

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by jamesalex » Thu Feb 16, 2023 10:41 pm

I saw that one.

IN:

Code: Select all

/system/library/url.php
BEFORE:

Code: Select all

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

Code: Select all

$url = str_replace('language=en-gb', '', $url);
$url = str_replace('&&', '&', $url);
I edited the url.php and put those 2 lines before the foreach as instructed above. It threw me a massive error so I had to remove it. I suspect I'm not reading the instructions above correctly.

Code: Select all

$url = str_replace('language=en-gb', '', $url);
$url = str_replace('&&', '&', $url);
foreach ($this->rewrite as $rewrite) {
    $url = $rewrite->rewrite($url);
}

New member

Posts

Joined
Thu Apr 19, 2012 9:03 pm

Post by by mona » Thu Feb 16, 2023 11:27 pm

Since Jonathan so kindly offered on that thread, the most sensible thing to do in my humble opinion would be to go back to that thread with your full four digit OC version and make the comment there and maybe Jonathan will be so kind as to assist you if you ask nicely, but as pointed out this is not going to resolve the issue totally although the canonical issue is not really a difficult issue to resolve either.
Nevertheless, you seem to miss the point that OC4 is not ready for a commercial site. Surely that decision is something that you are paid for ?

You can do whatever you like but seems in any clients best interest to use a robust version to me.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

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

I get that point now that oc4 is not ready for commercial use and therefore should be considered a beta.

However when I set this all up I assumed, like most people would, that the latest release is considered a workable release and can be used freely without hinderance.

At this stage it's far too late for me to scrap the site and go back to v3 so I'm stuck with what I've got and I need to find a solution to something I consider to be fairly minor as long as I can just work out the right commands in the .htaccess.

I shall go and add to the thread of the other conversation and see who can help there.

New member

Posts

Joined
Thu Apr 19, 2012 9:03 pm

Post by speakspaceAdmin » Sat Aug 19, 2023 3:51 pm

Opencart 4 is a bit of a pain with the SEO Url's. Here is what I did:
I deleted ALL of my SEO URL's in Design>SEO url (Although I deleted it via PHPMyAdmin to make it faster). Than I wrote a simple SQL script to insert the product SEO url's properly(I made the script because I have hundred of products. This will add the SEO url to both the product seo block and Design>SEO url.

Went through and re-added the SEO keywords to my categories and information pages again.
Make sure your .htaccess is set up and set OpenCart 4 settings to SEO. This fixed pretty much all of the SEO issues.

If you are upgrading from Opencart 3x to 4x you will need to DELETE all SEO than rebuild the SEO.

(I added the above as I did this after the original post below)
This is a SIMPLE fix for just removing en-gb!!!

NO CODE OPTION.
Go to Design>Seo url. Find the keyword en-gb. Select it and delete it.

If the No Code option does not work, use:
Replace the Code in /system/library/url.php

<?php
/**
* @package OpenCart
* @author Daniel Kerr
* @copyright Copyright (c) 2005 - 2022, OpenCart, Ltd. (https://www.opencart.com/)
* @license https://opensource.org/licenses/GPL-3.0
* @author Daniel Kerr
* @see https://www.opencart.com
*/

/**
* URL class.
*/
namespace Opencart\System\Library;
class Url {
private string $url;
private array $rewrite = [];

/**
* Constructor.
*
* @param string $url
*/
public function __construct(string $url) {
$this->url = $url;
}

/**
* Add a rewrite method to the URL system
*
* @param object $rewrite
*
* @return void
*/
public function addRewrite(\Opencart\System\Engine\Controller $rewrite): void {
$this->rewrite[] = $rewrite;
}

/**
* Generates a URL
*
* @param string $route
* @param string|array $args
* @param bool $js
*
* @return string
*/
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, '&');
}
}

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

if (!$js) {
return str_replace('/en-gb/product', '', str_replace('&', '&amp;', $url));
} else {
return str_replace('/en-gb/product', '',$url);
}
}

}


Posts

Joined
Sat Nov 26, 2022 7:24 pm

Post by fealldagal » Sat Feb 17, 2024 3:25 am

Has anyone figure it out? I am having the same issue and would like to have it fix, thank you in advance.

Newbie

Posts

Joined
Fri Oct 30, 2009 1:31 am

Post by xxvirusxx » Sat Feb 17, 2024 3:43 am

There was a suggestion (get refused) at Gihub for this: https://github.com/opencart/opencart/pull/13653/files

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by gwp » Sat Apr 13, 2024 6:24 pm

by mona wrote:
Thu Feb 16, 2023 11:27 pm
Nevertheless, you seem to miss the point that OC4 is not ready for a commercial site. Surely that decision is something that you are paid for ?
You can do whatever you like but seems in any clients best interest to use a robust version to me.
Ive been away from OC for a few years and have recently come back for a new project.
I downloaded the version default on the OC homepage (Version 4.0.2.3)

Can someone pease tell me if this is now a stable version, before i get too far into my new project?
Thanks

gwp
New member

Posts

Joined
Sun Jan 22, 2012 2:48 am

Post by straightlight » Sun Apr 14, 2024 8:14 am

gwp wrote:
Sat Apr 13, 2024 6:24 pm
by mona wrote:
Thu Feb 16, 2023 11:27 pm
Nevertheless, you seem to miss the point that OC4 is not ready for a commercial site. Surely that decision is something that you are paid for ?
You can do whatever you like but seems in any clients best interest to use a robust version to me.
Ive been away from OC for a few years and have recently come back for a new project.
I downloaded the version default on the OC homepage (Version 4.0.2.3)

Can someone pease tell me if this is now a stable version, before i get too far into my new project?
Thanks
I'd wait a bit longer before using a higher OC 4 version officially. It is still under development on the Github Opencart repository.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 5 guests