You say this happens with "the default Drupal front page" (that content feed). Realizing it now. The below is for those who have this problem with the front page set to display a specific node instead (at /admin/config/system/site-information
).
Possible cause: using a multilingual variable for setting the front page content, and forgetting to update it. In that case, when visiting example.com/en
, the Finnish version of the front page's node is displaying. However, when accessing that same node via (say) example.com/en/node/1
, the English version would show.
Explanation. Normally, one URL is configured as alias for the frontpage at /admin/config/system/site-information
. If this points to a content item with translations, they are shown as selected by the path prefix. With the multilingual variables however, one URL is configured per language version of the front page, completely overriding Drupal's normal language negotiation mechanism. The path prefix then selects the node given in the corresponding language version of the configuration option, even if that node is in a language not matching the path prefix. (Which leads to the funny effect that in the code rendering that front page node, $language
is "wrong": it is that node's language, here and only here potentially different from the language selected by the path prefix.)
Fix. To fix this condition and preventing it from recurring:
Go through all translations of your frontpage node and set them to the same alias, let's say, home
[source]. This should work, as each has a different language path prefix.
Go through the language versions of /admin/config/system/site-information
and update all "Default front page" fields to contain home
.
You probably have to repeat the last step for a new language after adding it. But I did not confirm this.
This whole multilingual variable thing is only to allow the front page being shown in different languages even when language is not selected by path prefix.
Or disable the multilingual versions of this variable altogether, by following this process in reverse.