Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical Problem with second store view: URL Rewrites not working! #11

Open
cptX opened this issue Apr 4, 2023 · 3 comments
Open

Critical Problem with second store view: URL Rewrites not working! #11

cptX opened this issue Apr 4, 2023 · 3 comments

Comments

@cptX
Copy link

cptX commented Apr 4, 2023

I faced a critical problem with this module.
I tried to create or modify the urls of some categories (create new and modify existing).
The first store view urls (greek - which I have as default and hidden in url) were working. But whatever I did for the second store view, whatever category url rewrites I created didn't work. The browser says "The page isn’t redirecting properly"
I have spent 2 days researching the issue and initially thought it was related with some rewrite issues that were found in magento recently, but after disabling the module all problems were solved.
So to make it more specific:

Create 2 store views. (let's say one el(greek) and one en (english))
Create a new category in greek (default) save and then change store view to en create a different url for the same category and save. The checkbox "Create Permanent Redirect for old URL" doesn't make any difference to the problem but I suggest to have it unchecked before saving.
Then visit the site. By default it will visit the greek version which is the default and without storeview suffix in url.
Visit the new created category. Then change language to english. Theoretically the browser will produce the error "The page isn’t redirecting properly" and it will fail to load the english category...

The problem is a bit strange because for some links it was impossible to access the english categories but for others the links worked ok both in greek and english. I really don't understand what happened. I suppose that I had created some categories before installing this module, and these work correctly. After installing it the new english categories which I created didn't work.

I have spent a full day playing with the url rewrites, I investigated the url_rewrite table in the database without finding any problems there. So I'm 100% sure this module is causing the issue...

This is critical for me because I was planning to use this module in production but now if I cannot access any of my second store view categories I will have a huge problem.

I have magento 2.4.6 and Luma Theme.

@karlsan
Copy link

karlsan commented May 5, 2023

Hi @cptX , not sure if this is the same issue, but we had a lot of problems with redirects not working after an upgrade from Magento 2.3 to 2.4. I also couldn't figure out what the issue was, it seemed relatively random, some products worked and some didn't.

In the end, we had someone help us bugfix and made a change to app/code/Noon/HideDefaultStoreCode/Observer/RedirectWithoutStoreCode.php. On line #58:

$pos = strpos($url, $this->storeManager->getStore()->getBaseUrl() . $defaultStore->getCode());

we changed it to:

$pos = false;
$urlParts = parse_url($this->url->getCurrentUrl());
if (isset($urlParts['path'])) {
	$pathParts = explode('/', ltrim($urlParts['path'], '/'), 2);
	if (isset($pathParts[0]) && $pathParts[0] == $defaultStore->getCode()) {
		$pos = true;
	}
}

This at least solves our problems it seems.

@cptX
Copy link
Author

cptX commented May 5, 2023

Hi @karlsan , unfortunately this issue was too important to ignore and as I had to publish my website I ended up showing the language prefix in the url. I was too afraid of other implications and I also checked the code and considered it unefficient so I decided to go with the standard magento method which is to show the language prefix, although I really would like to not have it in the url... So I'm afraid I will not check your solution, but I thank you nevertheless...

@alex-79
Copy link
Owner

alex-79 commented Jun 26, 2023

Hi @karlsan.

I used your code in the release 1.0.6. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants