How can I fix 404 errors with URL translation and redirection?

Topic summary

A multilingual e-commerce shop is experiencing 404 errors when users switch languages via a custom language selector. The issue occurs because translated URLs (e.g., German “vitamine-nahrungserganzungsmittel”) don’t redirect to their correct English equivalents (“vitamins-supplements”) when switching back to the default language.

Root Cause:
The custom language switcher uses hardcoded request paths across different subdomains (medpak.shop, de.medpak.shop, cz.medpak.shop, etc.) instead of Shopify’s localization endpoint, which handles translated URL handles properly.

Proposed Solutions:

  • Staff recommendation: Use Shopify’s standard localization endpoint as documented in their theme documentation, rather than custom code with hardcoded paths. The language switcher is being treated like a country switcher (subdomain-based), which may not be the intended setup.

  • Alternative approach: A community member (Transcy) suggested restructuring the code using a {% case locale.locale %} statement to handle each language individually.

Current Status:
The alternative code solution was tested but reportedly doesn’t work—individual languages fail to display. The issue remains unresolved and requires further troubleshooting of the language switching mechanism.

Summarized with AI on November 18. AI used: claude-sonnet-4-5-20250929.

I have several languages in the shop. I started to translate the URLs into each language, but there was a problem with redirection.

Now, when someone accesses the URL:
https://de.medpak.shop/collections/vitamine-nahrungserganzungsmittel/

and then wants to go back to that URL using the language change in the bottom left corner:
https://medpak.shop/collections/vitamine-nahrungserganzungsmittel

This gets a 404 error. Is it possible to make it so that the redirect always works correctly though?
https://medpak.shop/collections/vitamine-nahrungserganzungsmittel

and it should go to:
https://medpak.shop/collections/vitamins-supplements

This is what my code for changing the language looks like:

{% form 'localization', id: "localization_form_tag", class: "dropup" %}
<button class="language-button"><a href="#">{{ form.current_locale.endonym_name }}</a></button>
<div class="dropup-content">
  {% for locale in shop.published_locales %}
  <a href="https://medpak.shop{{ request.path }}" id="localeItem">{{ locale.endonym_name }}</a>
  <a href="https://cz.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/202-czech_republic.svg" width="32" height="32">Czech</a>
  <a href="https://de.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/208-germany.svg" width="32" height="32">Deutsch</a>
  <a href="https://nl.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/077-netherlands.svg" width="32" height="32">Dutch</a>
  <a href="https://ee.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/004-estonia.svg" width="32" height="32">Estonian</a>
  <a href="https://medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/110-united_kingdom.svg" width="32" height="32">English</a>
  <a href="https://fr.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/197-france.svg" width="32" height="32">French</a>
  <a href="https://it.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/263-italy.svg" width="32" height="32">Italian</a>
  <a href="https://lt.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/238-lithuania.svg" width="32" height="32">Lithuanian</a>
  <a href="https://sk.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/218-slovakia.svg" width="32" height="32">Slovak</a>
  <a href="https://es.medpak.shop{{ request.path }}" id="localeItem"><img src="https://cdn.shopify.com/s/files/1/0560/5788/8819/files/230-spain.svg" width="32" height="32">Spanish</a>
  {% endfor %}
  </div>
{% endform %}

Hi @kazunari , it looks like it might be your language switcher. When we test the language switchers on Dawn we hit the localization endpoint which is what’s responsible for ensuring that the translated handle references the correct resource.

Here’s the doc on it: https://shopify.dev/docs/themes/markets/multiple-currencies-languages#the-language-selector

We think it’s because there’s hard coded request paths, e.g: cz.medpak.shop{{ request.path }} , plus a number of subdomain markets where the language switcher is being treated like a country switcher to switch between domains. A country switcher would likely make more sense here. A language switcher isn’t really meant to switch between countries.

Hope that helps - we can’t provide too much support for custom code, but hopefully this gives an overview of the issue.

Hello @kazunari ,

You can try to modify the code like this:

{% form 'localization', id: "localization_form_tag", class: "dropup" %}

  {% for locale in shop.published_locales %}
    {% case locale.locale %}
      {% when 'en' %}
        [
![110-united_kingdom.svg|512x512](upload://d6s4bOzMrPkMfXeScs3DMZDXJ98.svg)
English](https://medpak.shop{{ request.path }})
      {% when 'cz' %}
        [
![202-czech_republic.svg|512x512](upload://fD3552VbILraig3e69Hq5lGHqXS.svg)
Czech](https://cz.medpak.shop{{ request.path }})
      {% when 'de' %}
        [
![208-germany.svg|512x512](upload://q9jTcZVyXQCsP8N1yE0UdBmjV0v.svg)
Deutsch](https://de.medpak.shop{{ request.path }})
      {% when 'nl' %}
        [
![077-netherlands.svg|512x512](upload://mWybuiUYKGzPLAWEbDnSfIlxeO5.svg)
Dutch](https://nl.medpak.shop{{ request.path }})
      {% when 'ee' %}
        [
![004-estonia.svg|512x512](upload://dICZw0vEogXAgvzlgXKXb1KeIyt.svg)
Estonian](https://ee.medpak.shop{{ request.path }})
      {% when 'fr' %}
        [
![197-france.svg|512x512](upload://35VdrHp6bwuxktJQPkmknCuzC6N.svg)
French](https://fr.medpak.shop{{ request.path }})
      {% when 'it' %}
        [
![263-italy.svg|512x512](upload://gA70U72HdcDhEH14ZrXpxFUrlNf.svg)
Italian](https://it.medpak.shop{{ request.path }})
      {% when 'lt' %}
        [
![238-lithuania.svg|512x512](upload://5NaRGEplZZBhikR12TcwSu9YAXe.svg)
Lithuanian](https://lt.medpak.shop{{ request.path }})
      {% when 'sk' %}
        [
![218-slovakia.svg|512x512](upload://9OyH8OKFkLKVtuuVTkmNn1J3SEQ.svg)
Slovak](https://sk.medpak.shop{{ request.path }})
      {% when 'es' %}
        [
![230-spain.svg|512x512](upload://f9sTzjv2BGKP5iV9EbQNOxlPH9l.svg)
Spanish](https://es.medpak.shop{{ request.path }})
    {% endcase %}
  {% endfor %}

{% endform %}

Let us know if it works

Hope this can help.

Transcy

This method does not work because the individual languages do not display.