Currently when adding a redirection there is a Language setting. If I understand correctly this setting is used to determine which language that should trigger the redirect rule which is done by the incoming url. So if it is set to English it will trigger a redirection if the incoming url is determined to be targeting the english language.

If the above is correct it means that the target url will always be to a page in the same language as the determined incoming url.

In a current project we have a lot of incoming urls that looks like this: /zh-hans
These urls trigger 404's since our site has the chinese prefix /cn
I want to redirect these urls to the front page in chinese: <front>

It seems that this is not possible using the Redirect module. If I add a rule with language set to english, the redirect will go to the english start page. If I set the language to chinese the redirect rule will not trigger, since /zh-hans is not considered to be a chinese page.

My suggestion is to add a Target language setting when adding a redirect rule. This setting would decide which language the redirection should point to, regardless of the language determined by the incoming url.

Hopefully this makes sense :)

Issue fork redirect-2845245

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

reekris created an issue. See original summary.

vegardjo’s picture

StatusFileSize
new53.29 KB

Not really sure if this is the same issue, as I don't see any language settings in the UI as described above. However, I also want to create a redirect that preserves the language the entity is in, which seems to not be possible now?

If I want to add a new redirect from taxonomy/term/1 to taxonomy/term/2 the UI gives me the option to create the redirect *from* the current language to an URL. However, I am not able to set a language prefix for the destination URL.

That is, I can set the destination manually to for instance /en/taxonomy/term/2, but that means that both language versions will redirect to the english version. Also, you can not make 2 redirects, one from /en/taxonomy/term/2 and one from /nb/taxonomy/term/2, as this will give you the message "The source path [...] is already being redirected. Do you want to edit the existing redirect?"

So in short: how to make a redirect that preserves the entity translation when doing the redirect? Seems to me the standard behaviour should be to keep the language prefix for both the source and the destination.

vegardjo’s picture

I reinstalled the module, at which point the language settings appeared to me as well. And now I am able to create double redirects for the same URL, one for each language.

bendev’s picture

I noticed the same issue.

I would expect that when language setting is set to "Not applicable " , the scenario described would be working independently of the language path prefix..

I have the same issue with a website where language prefix have changed. "fr-be" is now "fr" on the new site.
those redirects are not working. It would only work for the default language.
It redirects from en/fr-be/XXX to en/yyy
or from fr/fr-be/xxx to fr/yyy but we want a redirection from fr-be/xxx to fr/yyy

I also had the (wrong?) impression that it was working in d7. I think this used to work because it was mostly on websites with a default language set without any language path prefix.
Having a prefix for the default language set to 'en' creates this particular scenario.

If the module is not suppose to handle this scenario with parameter language set to "Not applicable", I would agree that a target language could be an option.

frederickjh’s picture

kerchack’s picture

I'm getting same issue as first one. In adition I have to comment that my problem is with same node with same alias and different translations, so, e.g: I've got '/de/home', '/fr/home' etc...

When 301 redirecting, I'm always getting '/home' alias path and I need the path with language code.

nkraft’s picture

My issue falls into this category, though maybe not exactly the scenario posed by the original poster.

We move an old site from .ASP into D8.

I need to redirect an old path like, /Espanol/page.asp
to /es/new-page

However! when putting /es/new-page into the destination, the site reverts to the default language of that page--
so instead, my direct is going from /Espanol/page.asp to /new-page

Is there a way to do this that I'm missing? or is this truly a bug of the redirect module, or soem other intertwined module?

wim leers’s picture

Issue tags: +D8MI
seanb’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

Since the destination URL is stored in a link field, we can set the preferred language of the destination in the link options. Since this would be really useful for 'regular' link fields, I created #2924653: Allow preferred language selection for link field to add this feature and posted a patch there.

Here is a patch that builds on top of the patch in #2924653-2: Allow preferred language selection for link field. Since the extra language field causes some usability issues in the redirect add/edit form, some improvements were made to the form as well.

berdir’s picture

Interesting approach, this is certainly a feature that would be useful to have and has been requested before. Kind of postponed on the core issue, though, for now.

Jānis Bebrītis’s picture

StatusFileSize
new1.98 KB

What I noticed, is, that Url object removes destination language and sets users site default language or language from souce. So there is no way to have redirect to different language.

I studied the patches above and took slightly different approach, by setting `$url->setOption('language', $language);` for url object. I extract `$language` from destination url.

Also, this only takes precedence when no language is specified in source. i.e. `/en/somepage` uses the default language negotiation, but `/somepage` takes the destination language from destination (as expected).

Status: Needs review » Needs work

The last submitted patch, 11: redirect_another_language-2845245-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

odavydyuk’s picture

Status: Needs work » Needs review
StatusFileSize
new4.28 KB

Status: Needs review » Needs work

The last submitted patch, 13: redirect_another_language-2845245-13.patch, failed testing. View results

odavydyuk’s picture

Status: Needs work » Needs review
StatusFileSize
new4.21 KB

Status: Needs review » Needs work

The last submitted patch, 15: redirect_another_language-2845245-15.patch, failed testing. View results

odavydyuk’s picture

Status: Needs work » Needs review
StatusFileSize
new4.18 KB

Status: Needs review » Needs work

The last submitted patch, 17: redirect_another_language-2845245-17.patch, failed testing. View results

yareckon’s picture

@Berdir which core issue?

pminf’s picture

@yareckon: Berdir was talking about #2924653, because the provided patch in #9 depends on it.

tikaszvince’s picture

StatusFileSize
new4.19 KB

Update patch#17 for version 8.x-1.3

seanb’s picture

luksak’s picture

It works for me on 1.3 and 8.6.12.

r.aubin’s picture

#21 worked for me using core 8.6.13 and trying to create a redirect from an english page to a translated page configured to use path prefixing (/es/page-name). Thank you!

thomasdik’s picture

StatusFileSize
new3.91 KB

As #21 did not work for me but did provide a solution I have altered it for newer versions.

ckng’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.84 KB

Attached a patch for D7.

ckng’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Needs review » Needs work
pminf’s picture

venugopp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

Updating patch #25 as per the version 8.x-1.6

Status: Needs review » Needs work

The last submitted patch, 29: 2845245-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ahaomar’s picture

Is that issue fixed bcz i also facing same issue. please guide me

rtdean93’s picture

I am facing the same issue

We have the site - domain.com and the french version at domain.com/fr - I am trying to use the redirect module and/or alias module to add an redirect from domain.com/my-old-french-url to domain.com/fr/my-new-french-url - but I am getting 404 every time. Anyone know what I am missing?

nwom’s picture

Is it possible to redirect the user to the "source language" as well, rather than based on the request path? I created an issue for this here: #3193334: Redirect to Source Language, but perhaps it would be better to incorporate within this patch? Thanks for any help on this!

navneet0693’s picture

Patch from https://www.drupal.org/project/redirect/issues/3163405#comment-13777184 should be further developed/re-rolled here.

pendaco’s picture

This is an annoying issue for sure. It also doesn't matter if you change the admin url to the other language when setting up the redirect. The url keeps redirecting to the node with the base language.

What worked for me though, as sort of a workaround, was specify the complete url in the destination.

My old structure had French Canadian as /fr-ca. The new one is at /fr

So for the path: fr-ca/path-old-url
To: https://www.website.com/fr/path-new-url

Seems to work.

ckng’s picture

Status: Needs work » Needs review
StatusFileSize
new2.41 KB

For my use case, have the need to redirect from one language to another language, /fr/produits > /products, /de/alle-produkte > /products, for examples.

The first route from patch #9 + core #2924653: Allow preferred language selection for link field works. Reroll patch #9 for 9.3.
The second route does not work in this case.

Status: Needs review » Needs work

The last submitted patch, 37: redirect_another_language-2845245-9-37.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hswong3i made their first commit to this issue’s fork.

hswong3i’s picture

Status: Needs work » Needs review

Convert to MR, rebase with 8.x-1.x-dev

biancaradu27’s picture

patch reroll

schoenef’s picture

For me the patches do not work - but if I use "undefined" as redirect language and don't select an actual node, but a locale path, it works.

For example:

Path: docs/DOC-1763

To: /de/node/2

Redirects then to the correct DE url alias of the node/2

This is not a good design and totally not obvious, but I guess this could count as "works as designed".

I'd preffer a selection "Destination Language" thou, if more then one language is defined in the site.

schoenef’s picture

I stand corrected - it only works together with the patch from #42 like I described above.

Together with the patch I managed now to import working locale redirects using migrations. If you are interested in the details, I've put it on drupal.stackexchange.com.

oknate made their first commit to this issue’s fork.