Links for translated content that are URL aliases get 404 errors.

CommentFileSizeAuthor
#1 country_code-aliases.patch698 bytesnedjo

Comments

nedjo’s picture

Status: Active » Fixed
StatusFileSize
new698 bytes

We needed to reset $_GET['q'] after resetting the language.

Attached patch appears to fix the issue.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

zroger’s picture

Title: Aliases broken for translated content » Aliases broken for translated content, re-opened
Priority: Normal » Critical
Status: Closed (fixed) » Active

I'm re-opening this issue since clearly there is no way that an aliased page can be properly un-aliased when using the same alias in different languages.

I think this is best illustrated by following an example request through the Drupal bootstrap process.

Lets say a request is made for /FR/about. There are 2 aliases in the system for about, one in fr-FR and one in en-US, the site default language.

Drupal Bootstrap Phases:
- DRUPAL_BOOTSTRAP_CONFIGURATION:
- DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:
- DRUPAL_BOOTSTRAP_DATABASE:
- DRUPAL_BOOTSTRAP_ACCESS:
- DRUPAL_BOOTSTRAP_SESSION:
- these dont effect the alias process

- DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
- hook_boot runs here, so long as aggressive caching isn't enabled. here we init the country code to FR, but dont touch the language

- DRUPAL_BOOTSTRAP_LANGUAGE:
- drupal runs through its language handling. Since we are not using any of the default language negotiation options, the global $language gets set to either the detected browser language, or the site default language. In this case, lets say the language gets set to en-US, the site default.

- DRUPAL_BOOTSTRAP_PATH:
- the path gets un-aliased in this phase. At this point, the language is still set to en-US, so $_GET['q'] is now set to the path aliased by the en-US about alias.

- DRUPAL_BOOTSTRAP_FULL:
- this is where hook_init() runs. Only at this point do we initialize the language to fr-FR. Its too late to affect the path alias, without directly setting $_GET['q].

Seems like we have some thinking to do...

nedjo’s picture

We do indeed reset $_GET['q] right after we reset the language at hook_init(), which seems to solve this issue.

nedjo’s picture

Are we getting errors? Is resetting in hook_init() too late?

zroger’s picture

Yes hook_init() is too late, since DRUPAL_BOOTSTRAP_PATH comes before DRUPAL_BOOTSTRAP_FULL (where hook_init is invoke).

Maybe I should clear up that the aliases are still being normalized, just that they are normalizing to the wrong path.

Example:
- English path: biography => node/1
- French path: biography => node/2

I verified this on an install by putting a dsm() in custom_url_rewrite_inbound, that showed that when $_GET['q'] was being normalized, it was using the site's default language (en-US in my case) to do the lookup, even when browsing in French. In particular, the path being looked for was 'biography', which is in the url_alias table several times, each with different languages. $_GET['q'] is then set to the english node path, node/1.

So the following code from _country_code_init_language() runs, we are trying to get the normal path of 'node/1', not 'biography'.

  // Reset the path with the correct language. This is needed e.g. to ensure that
  // language-specific aliases work.
  $_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'), $language->language);

We could possibly do something in custom_url_rewrite_inbound, which seems to be the logical place to put this kind of path handling. Possibly move the _country_code_init_language() call in here, so that the first time $_GET['q'] is normalized, we can fetch the correct alias src according to language.

nedjo’s picture

k, thanks, I'm following now.

The idea of moving language setting to our path rewriting indeed seems the most promising at this point.

Probably this is best done as part of #330156: Language not considered in page caching--users get wrong page. I've updated that issue (thought not with a lot of promising ideas).

catch’s picture

Status: Active » Postponed

This is very closely tied to the bootstrap issue, so marking postponed against that #330156: Language not considered in page caching--users get wrong page