Redirects do not preserve language

Created on 18 January 2023, almost 2 years ago
Updated 8 March 2023, over 1 year ago

Problem/Motivation

This was reported by a client. On a multilingual site, the language for redirects is not preserved so the redirects are not correct.

Steps to reproduce

  1. Install D9 with Umami Demo profile
  2. Install redirect module
  3. Install quant_api module
  4. Configure site to push content to quant
  5. Make sure to seed the redirects
  6. Go to: /es/node/1/edit
  7. Open Redirecciones de URL
  8. Click Add URL Redirect (note, text is not translated)
  9. Enter redirect testing-spanish-redirect, choose Espaรฑol for the language, and save
  10. Go to: /es/testing-spanish-redirect and it should redirect you to /es/recipes/quiche-mediterrรกneo-profundo (node/1)
  11. Create an English redirect via /en/node/1/edit in the same way using testing-english-redirect and English language
  12. Go to: /en/testing-english-redirect and it should redirect you to /en/recipes/deep-mediterranean-quiche (node/1)
  13. Create a general redirect via /en/node/1/edit in the same way using testing-general-redirect and "All languages"
  14. Go to: /en/testing-general-redirect and it should redirect you to /en/recipes/deep-mediterranean-quiche (node/1)
  15. Go to: /es/testing-general-redirect and it should redirect you to /es/recipes/quiche-mediterrรกneo-profundo (node/1)
  16. You now have different redirects for the same node for Spanish, English, and all languages
  17. Run the queue, e.g. drush quant:run-queue
  18. In the Quant Dashboard, go to /redirects and you should see the redirects listed but they all have /en/ as the language prefix

Proposed resolution

Update the redirect logic so the language prefix of the redirect is included. Note that if All languages is chosen, a redirect will need to be created for every single enabled language.

Test the following use cases

Language configuration

  1. Non-multilingual site
  2. Multilingual site, one language, no language path prefix
  3. Multilingual site, one language, language path prefix
  4. Multilingual site, multiple languages, no language path prefix
  5. Multilingual site, multiple languages, language path prefix

Redirects for non-multilingual site (language/translation modules uninstalled)

  1. One node without a redirect, shouldn't create a redirect except for node/[nid]
  2. One node with redirect, should create redirect and node/[nid] redirect

Redirects for multilingual site, one language, no language path prefix (language/translation modules installed)

  1. One node without a redirect, shouldn't create a redirect except for node/[nid]
  2. One node with 1 redirect with language chosen, should create redirect without path prefix and node/[nid] redirect
  3. One node with 1 redirect with all languages chosen, should create redirect without path prefix and node/[nid] redirect

Redirects for multilingual site, one language, language path prefix (language/translation modules installed)

  1. One node without a redirect, shouldn't create redirects except for node/[nid] and [langcode]/node/[nid]
  2. One node with 1 redirect with language chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]
  3. One node with 1 redirect with all languages chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]

Redirects for multilingual site, multiple languages, no language path prefix

  1. One untranslated node without a redirect, shouldn't create a redirect except for node/[nid]
  2. One translated node without a redirect, shouldn't create a redirect except for node/[nid]
  3. One untranslated node with 1 redirect with language chosen, should create redirect without path prefix and node/[nid] redirect
  4. One translated node with 1 redirect with language chosen, should create redirect without path prefix and node/[nid] redirect
  5. One untranslated node with 1 redirect with all languages chosen, should create redirect without path prefix and node/[nid] redirect
  6. One translated node with 1 redirect with all languages chosen, should create redirect without path prefix and node/[nid] redirect
  7. One untranslated node with 3 redirects for each language, should create 3 redirects without path prefix and node/[nid] redirect
  8. One translated node (only 2 of the languages) with 3 redirects for each language, should create 3 redirects without path prefix and node/[nid] redirect

Redirects for multilingual site, multiple languages, language path prefix

  1. One untranslated node without a redirect, shouldn't create a redirect except for node/[nid] and [langcode]/node/[nid]
  2. One translated node without a redirect, shouldn't create a redirect except for node/[nid] and [langcode]/node/[nid]
  3. One untranslated node with 1 redirect with language chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]
  4. One translated node with 1 redirect with language chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]
  5. One untranslated node with 1 redirect with all languages chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]
  6. One translated node with 1 redirect with all languages chosen, should create redirect with path prefix and node/[nid] and [langcode]/node/[nid]
  7. One untranslated node with 3 redirects for each language, should create 3 redirects with path prefix and node/[nid] and [langcode]/node/[nid]
  8. One translated node (only 2 of the languages) with 3 redirects for each language, should create 3 redirects with path prefix and node/[nid] and [langcode]/node/[nid]

Remaining tasks

  1. Debug
  2. Choose approach for fix
  3. Create patch
  4. Review and test
  5. Commit :)

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Fixed

Version

1.5

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States Kristen Pol Santa Cruz, CA, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024