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

Redirect requests to default language URI in secondary languages to the custom secondary language slug #3550

Open
lukasbestle opened this issue Jul 19, 2021 · 8 comments · Fixed by #6601
Assignees
Labels
type: bug 🐛 Is a bug; fixes a bug

Comments

@lukasbestle
Copy link
Member

Basic example

URLs:

/page/subpage
/de/seite/unterseite

Request mapping right now:

/page/subpage ✅
/de/seite/unterseite ✅

/de/page/subpage    -> serves the page /de/seite/unterseite
/de/seite/subpage   -> same here
/de/page/unterseite -> same here

Expected behavior:

The last three examples should be HTTP 302 redirects to the canonical URL /de/seite/unterseite.

Complex example

This works at the moment and there needs to be a unit test to verify that we don't break this behavior.

URLs:

/page1
/de/seite1

/page2
/de/page1 (translation of page2!)

Expected routing:

/page1 ✅
/de/seite1 ✅

/page2 ✅
/de/page2 -> 302 to /de/page1
/de/page1 ✅ (should *not* redirect to /de/seite1, which is a different page)

Background context

See #2257.

@stale
Copy link

stale bot commented Jul 19, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the type: stale 💤 Will be closed soon because there was no recent activity label Jul 19, 2022
@lukasbestle
Copy link
Member Author

Not stale

@stale stale bot removed the type: stale 💤 Will be closed soon because there was no recent activity label Jul 30, 2022
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. This is for us to prioritize issues that are still relevant to our community. It will be closed if no further activity occurs within the next 14 days. If this issue is still relevant to you, please leave a comment.

@github-actions github-actions bot added the type: stale 💤 Will be closed soon because there was no recent activity label Jan 27, 2023
@lukasbestle lukasbestle removed the type: stale 💤 Will be closed soon because there was no recent activity label Jan 27, 2023
@schokomeldra
Copy link

I am not convinced that this behavior is normal, it is rather very strange. I don't know it from other CMS.
On the one hand, it is not good when such "wrong" pages are indexed because on a page marked as English, there should be no German texts, for example.
In addition, customers do not understand it when they suddenly land on such a page because they do not understand the error behind it.

Maybe you could make it so that you can turn off the behavior if you don't want it?

@lukasbestle
Copy link
Member Author

@schokomeldra I think there is a misunderstanding. This is not about pages with mixed translation texts or missing translations, but about canonical URLs to translated pages. At the moment, you can reach the exact same translated page via different combinations of nested paths (with the original slug and the translated slug of each level). By redirecting all invalid/inconsistent paths to the canonical path, users will still get to the correct page but with the correct URL.

@FNGR2911
Copy link

@schokomeldra I think there is a misunderstanding. This is not about pages with mixed translation texts or missing translations, but about canonical URLs to translated pages. At the moment, you can reach the exact same translated page via different combinations of nested paths (with the original slug and the translated slug of each level). By redirecting all invalid/inconsistent paths to the canonical path, users will still get to the correct page but with the correct URL.

I've just stumbled across the same problem! I agree with you, the behavior should be exactly as you described:
A translated page with a translated slug should only be accessible under that slug and the original slugs should redirect to the translation via 301/302.

@Vincenius
Copy link

Vincenius commented Mar 13, 2024

Same here. As a workaround, I added the following code to my site/controllers/site.php:

$correctUrl = $page->url();
$requestPath = $kirby->path();
if (
    strpos($correctUrl, $requestPath) === false &&
    strpos($correctUrl, '/error') === false // don't redirect to /error -> keep wrong uri if not exist
) {
    // keep query string if it exists
    $query = $_SERVER['QUERY_STRING'] ? "?" . $_SERVER['QUERY_STRING'] : "";
    return $kirby
        ->response()
        ->redirect($correctUrl . $query);
}

Works for me, but use it with caution - I'm new to Kirby & PHP

@FNGR2911
Copy link

Same here. As a workaround, I added the following code to my site/controllers/site.php:

$correctUrl = $page->url();
$requestPath = $kirby->path();
if (
    strpos($correctUrl, $requestPath) === false &&
    strpos($correctUrl, '/error') === false // don't redirect to /error -> keep wrong uri if not exist
) {
    // keep query string if it exists
    $query = $_SERVER['QUERY_STRING'] ? "?" . $_SERVER['QUERY_STRING'] : "";
    return $kirby
        ->response()
        ->redirect($correctUrl . $query);
}

Works for me, but use it with caution - I'm new to Kirby & PHP

Thank you @Vincenius. I'll take a look at it und test it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants