Problem

Currently the language for a redirect applies to both, source (From) and redirect (To). If you want to redirect to a german page let's say - then the actual redirect source needs to be a german path as well. When you want to use redirect module to redirect legacy paths to new drupal paths, this is a blocker.

Example

An example: You want to redirect "the-old-german-path.html" to the "de/new-fancy-drupal-path" (alias for node/123 in language German). If you try to use the old path as a "From" source, the new path as "To", and choose German as a language, then the redirect is only triggerd on 'de/the-old-german-path.html' - as the language you have chosen for the redirect is German.

Proposed Solution

As a proposed solution, I added a new setting to each redirect, called "Language neutral source". If this checkbox is set, then the redirect is triggered without language prefix. The language in the prefix is still used for the target (To) path.

Before: de/the-old-german-path.html redirects to de/new-fancy-drupal-path
After: the-old-german-path.html redirects to de/new-fancy-drupal-path

A patch follows...

Comments

valderama’s picture

Status: Active » Needs review
StatusFileSize
new4.8 KB
mxt’s picture

After applying your patch I can't access my site any more, receiving the following error:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'language_neutral_source' in 'where clause': SELECT redirect.rid AS rid FROM {redirect} redirect WHERE ( (source LIKE :db_condition_placeholder_0 ESCAPE '\\') OR (source = :db_condition_placeholder_1) )AND( (language IN (:db_condition_placeholder_2, :db_condition_placeholder_3)) OR (language_neutral_source = :db_condition_placeholder_4) ); Array ( [:db_condition_placeholder_0] => front-page [:db_condition_placeholder_1] => [:db_condition_placeholder_2] => it [:db_condition_placeholder_3] => und [:db_condition_placeholder_4] => 1 ) in redirect_load_by_source() (line 577

Can you please reroll your patch againist LATEST dev version of redirect module?

I really need to try this patch to resolve the issue you described (and also described here: https://drupal.org/node/1682288 )

Thank you very much

MXT

mxt’s picture

After manually create the missing column in redirect table, my sites restarts to working.

I've checked the "From" is language neutral new option in my node, but the main issue is not resolved, receiving the following error:

Notice: Undefined index: und in redirect_redirect() (line 1013 of /var/www/mysite/sites/all/modules/contrib/redirect/redirect.module).

mxt’s picture

The above error is triggered only if you choose "all languages" in redirect settings in node admin page.

Instead, if you select a specific language, the error disappears and your patch WORKS GREAT!!!

Thank you very much!

mxt’s picture

Status: Needs review » Needs work

The error triggered using "all languages" have to be managed, and upgrade path should create itself the new column in redirect table.

Vincenzo’s picture

I am working on this one.

Vincenzo’s picture

Status: Needs work » Needs review
StatusFileSize
new5.7 KB

A new version of the originally proposed patch.
It includes an upgrade path now and some minor stuff.
I couldn't reproduce the other issue that MXT was mentioning about "All languages".
Please test this one.

Status: Needs review » Needs work

The last submitted patch, language-neutral-source-1983444-2.patch, failed testing.

brightbold’s picture

Using the patch in #7, I am having the same problem as MXT with the PDO error. It seems like an error you would get if you had failed to run update.php, but I did that and I cleared the cache. I, too, first attempted to create an 'All Languages' redirect (before I remembered to run update.php, oops).

brightbold’s picture

OK I can't figure this out. There is a column language_neutral_source in the redirect table, so I don't know why I'm getting this error or what I can do to prevent it. For now I'll have to roll back this patch and live without un-prefixed redirects.

erichomanchuk’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new5.69 KB

The field name in the update hook was misspelled so when you ran the update you would get an error about a missing field when visiting the redirect config page. I changed the update hook to add the correct field to the redirect table.

Remember to run update.php or drush updb and then clear caches.

Status: Needs review » Needs work

The last submitted patch, 11: language-neutral-source-1983444-3.patch, failed testing.

antondavidsen’s picture

StatusFileSize
new5.67 KB

Fixed the warning described in #3

webadpro’s picture

Is there a way to test the latest patch?

knalstaaf’s picture

Both #13 and #11 aren't working for me (ran update.php / cleared cache).

The situation is so that I have to redirect paths that are not existing on the current installation. They're from a previous (Wordpress) installation (which didn't have a language prefix in the default language).

This module looked very much like what I needed to redirect old links in the search engine's results to the proper new pages. Maybe I should ask...

valderama’s picture

Status: Needs work » Needs review

Lets see what the testbot says...

valderama’s picture

Status: Needs review » Reviewed & tested by the community

Yay, testbot is fine with the patch!

I just tested it manually and it is working as expected, so I'll put it as reviewed and tested by the community.

knalstaaf’s picture

I'm getting this error visiting the redirect config page after applying patch #13 on Redirect 7.x-1.0-rc1+8-dev (2014-Jul-23):

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base.language_neutral_source' in 'field list': SELECT base.rid AS rid, base.hash AS hash, base.type AS type, base.uid AS uid, base.source AS source, base.source_options AS source_options, base.redirect AS redirect, base.redirect_options AS redirect_options, base.language AS language, base.status_code AS status_code, base.count AS count, base.access AS access, base.language_neutral_source AS language_neutral_source FROM {redirect} base WHERE (base.rid IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11, :db_condition_placeholder_12, :db_condition_placeholder_13, :db_condition_placeholder_14, :db_condition_placeholder_15, :db_condition_placeholder_16, :db_condition_placeholder_17, :db_condition_placeholder_18, :db_condition_placeholder_19, :db_condition_placeholder_20, :db_condition_placeholder_21, :db_condition_placeholder_22, :db_condition_placeholder_23, :db_condition_placeholder_24, :db_condition_placeholder_25, :db_condition_placeholder_26)) ; Array ( [:db_condition_placeholder_0] => 23 [:db_condition_placeholder_1] => 18 [:db_condition_placeholder_2] => 20 [:db_condition_placeholder_3] => 2 [:db_condition_placeholder_4] => 21 [:db_condition_placeholder_5] => 22 [:db_condition_placeholder_6] => 24 [:db_condition_placeholder_7] => 19 [:db_condition_placeholder_8] => 17 [:db_condition_placeholder_9] => 16 [:db_condition_placeholder_10] => 15 [:db_condition_placeholder_11] => 9 [:db_condition_placeholder_12] => 12 [:db_condition_placeholder_13] => 14 [:db_condition_placeholder_14] => 1 [:db_condition_placeholder_15] => 7 [:db_condition_placeholder_16] => 8 [:db_condition_placeholder_17] => 11 [:db_condition_placeholder_18] => 13 [:db_condition_placeholder_19] => 10 [:db_condition_placeholder_20] => 6 [:db_condition_placeholder_21] => 5 [:db_condition_placeholder_22] => 26 [:db_condition_placeholder_23] => 28 [:db_condition_placeholder_24] => 27 [:db_condition_placeholder_25] => 3 [:db_condition_placeholder_26] => 4 ) in DrupalDefaultEntityController->load() (line 191 van /home/domain/public_html/includes/entity.inc).

It's also impossible to empty the Drupal cache (I'm getting a 404).

tommeir’s picture

Thank you for that patch! you saved my client's site url migration :)

knalstaaf - it works but you need to execute update.php to let it install the new table column.

valderama’s picture

StatusFileSize
new5.99 KB

I manually re-examined and re-tested the current patch. The changes still makes sense to me and I would be really glad to at least get feedback from the maintainer.

I have made minor changes: added a comment and re-named the hook_update_N function to apply to current dev.

@knalstaaf - Please re-try with this patch - I think your problem was that the update hook was not executed, due to an outdated naming of it.

valderama’s picture

Status: Reviewed & tested by the community » Needs review

Setting to "needs review" to trigger test bot.

valderama’s picture

Issue summary: View changes
valderama’s picture

Issue summary: View changes
TheBarnacle’s picture

@knalstaaf did you ever get yours to work? I just added the #20 patch and am getting the same error as on #18.

TheBarnacle’s picture

Never mind - I hadn't run the db update. Now it works!

deanflory’s picture

This patch fails when applied to the redirect module (dev) after this other issue's patch:

fix_and_prevent-1796596-249.patch
#1796596: Fix and prevent circular redirects

Results of this issue's patch run after applying the noted other issue's patch:

patching file redirect.admin.inc
Hunk #1 succeeded at 79 (offset 1 line).
Hunk #2 succeeded at 408 (offset 11 lines).
Hunk #3 FAILED at 549.
1 out of 3 hunks FAILED -- saving rejects to file redirect.admin.inc.rej
patching file redirect.install
Hunk #1 succeeded at 95 with fuzz 2 (offset 7 lines).
Hunk #2 succeeded at 217 (offset 8 lines).
patching file redirect.module
Hunk #1 succeeded at 575 (offset 24 lines).
Hunk #2 succeeded at 730 (offset 24 lines).
Hunk #3 succeeded at 1122 (offset 140 lines).
Hunk #4 succeeded at 1175 (offset 144 lines).
Hunk #5 succeeded at 1196 (offset 144 lines).

This patch did not fix my error. I'm now getting this when I try and go to my account page:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'language_neutral_source' in 'where clause': SELECT redirect.rid AS rid FROM {redirect} redirect WHERE (source LIKE :db_condition_placeholder_0 ESCAPE '\\') AND( (language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) OR (language_neutral_source = :db_condition_placeholder_3) ); Array ( [:db_condition_placeholder_0] => path/here [:db_condition_placeholder_1] => en [:db_condition_placeholder_2] => und [:db_condition_placeholder_3] => 1 ) in redirect_load_by_source() (line 559 of /.../sites/all/modules/redirect/redirect.module).

Michsk’s picture

Seems to work as expected for me.

Just as a side note i would recommed changing the label for the checkbox:
Source URL is language neutral

To something more close to the source field. So something like:
From URL is language neutral

That would make it easier for users who dont understand what that checkbox does.

Michsk’s picture

Latest patch does not work when page caching is enabled for anonymous users.

bohus ulrych’s picture

Hi all,
#20 seems to be working well on my installation (latest drupal + latest modules) even with caching module Boost.
Thank you
P.S. !! Do not forgot to update db after patching !!

mattew’s picture

StatusFileSize
new7.44 KB

I added two fixes to this patch, when the checkbox was checked:

  1. Source URL was processed through drupal_get_normal_path, resulting to a wrong source URL saved when another node use the same path as an alias for the same language.
  2. Language prefix was added to the URL in the URL Redirects table on forms.
Marko B’s picture

I worked here on similar thing https://www.drupal.org/node/2458325 slightly different approach.

mfernea’s picture

#20 works for us too. We don't have Boost or page caching enabled.

Maybe for #30 it's best to have an interdiff too.

mattew’s picture

I think that adding a patch that rely on another one (#20) will not pass the tests. #30 contains all changes from #20, with some extra fixes, you can apply #30 instead of #20 without trouble.

mfernea’s picture

I would like to see the interdiff because it shows just the changes added by #30, so it's easier to review. It can't be used for anything else (afaik).

bessone’s picture

#30 worked for me on last stable (7.x-1.0-rc1)

mattew’s picture

@mfernea
As you already mentioned, a diff between two patch is useless, and as I said, I will not post such a patch as it will not pass the tests. So, DIY ! ;) http://www.quickdiff.com/

mfernea’s picture

Creating interdiffs is part of best practices when contributing.
https://www.drupal.org/documentation/git/interdiff

I will do it. :)

mfernea’s picture

StatusFileSize
new1.59 KB

Here is the interdiff between #30 and #20.

mattew’s picture

OK, my bad, I didn't know that I could supply an interdiff in .txt format.
Best regards

mattew’s picture

Category: Feature request » Task
Priority: Normal » Critical

This ticket is two years old... Please could you commit something?
The last RC2 implements a 7101 update hook to add a "status" field and could not work without it... so it is a big problem when we use this patch, which implements the same hook.

This patch is essential when you use this module to redirect URLs from an old non-drupal site to a multi-lingual one.

mfernea’s picture

Here is the patch from #30 rerolled onto 7.x-1.0-rc3.
I'm trying to figure out what's the best upgrade path for those that applied the patch while using 7.x-1.0-rc1 and now want to update the module.

mfernea’s picture

Here is the patch for 7.x-1.0-rc3 ONLY for those who applied either #20 or #30 patch while using 7.x-1.0-rc1 version.

mfernea’s picture

I should have suffixed the patch name from #42 with "do-not-test".

damienmckenna’s picture

ckrina’s picture

Patch from #41 is working for me, in a clean install and in a production site. Thanks!
Maybe another tester would be better before moving to RTBC.

vijaycs85’s picture

Status: Needs review » Needs work
  1. +++ b/redirect.admin.inc
    @@ -405,6 +412,12 @@ function redirect_edit_form($form, &$form_state, $redirect = NULL) {
    +    '#description' => t('If checked, the %from field is considered to be language neutral.', array('%from' => 'From')),
    

    No need for placeholder here.

  2. +++ b/redirect.admin.inc
    @@ -522,7 +535,7 @@ function _redirect_extract_url_options(&$element, &$form_state) {
    +  if (!url_is_external($parsed['url']) && ($type != 'source' || $form_state['values']['language_neutral_source'] === 0)) {
    

    I don't think '===' works here as the form_state always send the form values as string.

zrpnr’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7.9 KB
new1.1 KB

Tested the patch in #41, seems to work very well, thanks!
Wondering why all source urls are not treated as language neutral by default? Seems like better behavior.
Marking this RTBC.

Regarding edits suggested by @vijaycs85 in #46, I don't think these are major blockers but I rerolled the patch with those changes to help get this work committed.

1. Placeholder using a string value was just emphasizing the text, replaced it.
2. When I debugged the 0 was not a string, it should work with either == or ===.

Made no other code changes, interdiff attached.

zrpnr’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new8.1 KB
new1.42 KB

If this code is deployed, there are some database errors related to the new column.
Running update.php will fix- but it is better if the code doesn't break the site before updates are run.

joachim’s picture

> If this code is deployed, there are some database errors related to the new column.
Running update.php will fix- but it is better if the code doesn't break the site before updates are run.

That is normal behaviour whenever a hook_update_n() makes database changes. Site builders are expected to put their site into maintenance before applying code updates, and only bring it back live once the updates have run.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Patch works great.

(Though anyone running this patch should be aware that there are at least TWO other issues for this project with RTBC patches which add redirect_update_7103(), so when these are eventually committed, your system updates will need some tinkering to work properly.)

joachim’s picture

I'm actually wondering now whether the 'language_neutral_source' option should be added to the 'source_options' serialized DB column, rather than its own column...

Is the source_options column just URL options though -- ie is the whole of that array passed to url() or similar?

dshields’s picture

I'm having issues with this patch.
When I try to run the updb via drush, I hit my php menory limit. While it eventually completes the update script in the browser, it certainly takes its time.

I'm wondering about joachim's comment about "system updates will need some tinkering to work properly" - could anyone expand on that? Should the update number be changed?

joachim’s picture

> I'm wondering about joachim's comment about "system updates will need some tinkering to work properly" - could anyone expand on that? Should the update number be changed?

Yes, that's exactly it. Two other patches in the issue queue (at the time I wrote that comment) also try to add the same number update hook. Depending on what order the maintainer commits them, some will need to be renumbered. Furthermore, anyone applying one of these patches will need to fiddle with their system table to make sure all the updates are run.

dshields’s picture

Ahh

misthero’s picture

patch 48 works on 7.x-2.x-dev.

please commit :)

attiks’s picture

#48 Works like a charm for 7.x-1.x

bserem’s picture

Issue tags: +needs port to 8.x-1.x

This needs to be patched on Drupal8 version of the module too, right?

pminf’s picture

I think Allow Redirecting to another language is about this issue in Drupal 8.

pifagor’s picture

Status: Reviewed & tested by the community » Needs work

Patch Failed to Apply

damienmckenna’s picture

Issue tags: +Needs reroll
q11q11’s picture

Patch from #20 is ok for 7.x-1.0-rc1.
Patch from #48 is ok for 7.x-1.0-rc3.

While running updates from rc1 to rc3 (with patch from #48 applied to rc3) got this:

Update #7102
Failed: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'status' in 'field list': UPDATE {redirect} SET status=:db_update_placeholder_0 WHERE (rid IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11, :db_condition_placeholder_12)) ; Array ( [:db_update_placeholder_0] => 0 [:db_condition_placeholder_0] => 24733 [:db_condition_placeholder_1] => 24737 [:db_condition_placeholder_2] => 24920 [:db_condition_placeholder_3] => 25027 [:db_condition_placeholder_4] => 25053 [:db_condition_placeholder_5] => 25115 [:db_condition_placeholder_6] => 25268 [:db_condition_placeholder_7] => 25269 [:db_condition_placeholder_8] => 25271 [:db_condition_placeholder_9] => 25273 [:db_condition_placeholder_10] => 25276 [:db_condition_placeholder_11] => 25277 [:db_condition_placeholder_12] => 25340 ) in redirect_update_7102() (line 322 of ... bla bla bla ... /redirect/redirect.install).
kapilv’s picture

Status: Needs work » Needs review
StatusFileSize
new8.08 KB

Hear a reroll patch.

kapilv’s picture

StatusFileSize
new9 KB
kapilv’s picture

Issue tags: -Needs reroll
wylbur’s picture

Status: Needs review » Closed (outdated)

Closing this as Outdated as Drupal 7 is EOL.