The Drupal 6 Global Redirect module provides a lot of features like:

  • Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
  • Checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request.
  • Checks if the current URL is the same as the site_frontpage and redirects to the frontpage if there is a match.
  • Checks if the Clean URLs feature is enabled and then checks the current URL is being accessed using the clean method rather than the 'unclean' method.
  • Checks access to the URL. If the user does not have access to the path, then no redirects are done. This helps avoid exposing private aliased node's.
  • Make sure the case of the URL being accessed is the same as the one set by the author/administrator. For example, if you set the alias "articles/cake-making" to node/123, then the user can access the alias with any combination of case.

This patch aims to add those features (and the ability to configure them) into the Redirect module.

CommentFileSizeAuthor
#284 interdiff_280-284.txt2.57 KBandralex
#284 redirect-d7-1.x-merge_global_redirect-905914-284.patch18.93 KBandralex
#280 redirect-d7-1.x-merge_global_redirect-905914-280.patch18.82 KBjedsaet
#278 redirect-d7-1.x-merge_global_redirect-905914-278.patch18.51 KBc7bamford
#275 redirect-d7-1.x-merge_global_redirect-905914-275.patch18.59 KBc7bamford
#273 redirect-d7-1.x-merge_global_redirect-905914-273.patch18.6 KBc7bamford
#264 redirect-merge_global_redirect-905914-264-d7.patch18.73 KBc7bamford
#260 redirect-global-905914-260.patch14.25 KBrajiv.singh
#258 interdiff.txt3.54 KBtomsegarra
#258 redirect-merge_global_redirect-905914-258-d7.patch18.73 KBtomsegarra
#254 interdiff.txt3.27 KBeelkeblok
#254 redirect-merge_global_redirect-905914-254-d7.patch16.95 KBeelkeblok
#246 interdiff.txt7.63 KBeelkeblok
#246 redirect-merge_global_redirect-905914-246-d7.patch14.16 KBeelkeblok
#242 interdiff.txt699 bytesr.van.doorn
#242 redirect-n905914-241.patch14.01 KBr.van.doorn
#227 redirect-n905914-227.patch13.76 KBDamienMcKenna
#195 interdiff-905914-190-195.txt2.91 KBvalentin schmid
#195 redirect-merge-global-redirect-905914-195.patch13.81 KBvalentin schmid
#18 905914.patch2.4 KBswentel
#20 905914.patch2.76 KBswentel
#26 enable_global_redirects-905914-26.patch3.12 KBpillarsdotnet
#27 redirect_object.patch1.3 KBpillarsdotnet
#29 enable_global_redirects-905914-29.patch3.84 KBpillarsdotnet
#30 enable_global_redirects-905914-30.patch3.84 KBamanaplan
#31 redirect-restore_global-redirect-905914-31.patch3.92 KBpillarsdotnet
#32 redirect-restore-global-redirect-905914-32.patch4.61 KBpillarsdotnet
#34 redirect-restore-global-redirect-905914-34.patch5.85 KBpillarsdotnet
#36 redirect-restore-global-redirect-905914-36.patch5.86 KBpillarsdotnet
#38 redirect-restore-global-redirect-905914-38.patch5.11 KBpillarsdotnet
#39 redirect-restore-global-redirect-905914-39.patch6.36 KBpillarsdotnet
#46 redirect-restore-global-redirect-905914-46.patch1.19 KBlliss
#47 redirect-restore-global-redirect-905914-39.patch6.36 KBpillarsdotnet
#56 redirect-restore-global-redirect-905914-56.patch5.88 KBrickvug
#63 redirect-frontpage.patch6.64 KBfasdalf@fasdalf.ru
#65 redirect-frontpage.patch6.6 KBfasdalf@fasdalf.ru
#71 global.patch9.12 KBfasdalf@fasdalf.ru
#73 global.patch8.54 KBfasdalf@fasdalf.ru
#75 global.patch8.54 KBfasdalf@fasdalf.ru
#77 redirect.zip42.31 KBfasdalf@fasdalf.ru
#78 reenable_global_redirections-905914-78.patch6.05 KBjenlampton
#80 redirections_with_frontpage-905914-80.patch6.82 KBjenlampton
#82 redirect-global-redirection-905914-82.patch6.84 KBvalor
#89 enable_global_redirections_with_frontpage-905914-88.patch7.13 KBjenlampton
#91 enable_global_redirections_with_frontpage-905914-91.patch6.94 KBjenlampton
#98 905914-redirect-reenable-global-redirections-97.patch9.3 KBbarraponto
#100 905914-redirect-reenable-global-redirections-100.patch7.27 KBpillarsdotnet
#102 905914-redirect-reenable-global-redirections-102.patch7.28 KBpillarsdotnet
#104 905914-redirect-reenable-global-redirections-104.patch7.53 KBpillarsdotnet
#107 redirect-reenable_global_redirections-905914-107.patch7.53 KBjenlampton
#120 redirect-reenable_global_redirections-905914-120.patch7 KBAlan D.
#121 redirect-reenable_global_redirections-905914-121.patch6.99 KBAlan D.
#129 redirect-global-905914-129.patch10.81 KBericras
#130 redirect-global-905914-130.patch12.65 KBericras
#145 redirect-global-905914-145.patch12.79 KBericras
#154 redirect-global-905914-154.patch13.43 KBezeedub
#154 interdiff-905914-145-154.txt1.36 KBezeedub
#155 redirect-global-905914-155.patch13.7 KBezeedub
#155 interdiff-905914-145-155.txt1.99 KBezeedub
#157 redirect-global-905914-157.patch13.74 KBezeedub
#157 interdiff-905914-145-157.txt2.21 KBezeedub
#161 redirect-global-905914-161.patch13.87 KBezeedub
#161 interdiff-905914-145-161.txt2.34 KBezeedub
#163 redirect-globalredirect-905914-163.patch13.98 KBjasonlttl
#163 interdiff-905914-161-163.txt986 bytesjasonlttl
#166 905914-166-redirect-global.patch14.58 KBbeeradb
#170 globalredirect-905914-170.patch14.6 KBjessehs
#171 interdiff-170-171.txt580 bytesjessehs
#171 globalredirect-905914-171.patch14.57 KBjessehs
#174 globalredirect--905914--171+162.patch14.02 KBvadym.kononenko
#178 merge-globalredirect--905914-178.patch14.85 KBkrisahil
#186 merge-globalredirect--905914-186.patch14.1 KBvadym.kononenko
#190 redirect-merge-globalredirect-905914-190.patch14.85 KBjantoine
#190 interdiff-905914-186-190.txt1013 bytesjantoine
#192 redirect-merge-global-redirect-905914-192.patch15.04 KBvalentin schmid
#193 redirect-merge-global-redirect-905914-193.patch13.95 KBvalentin schmid
#193 interdiff-905914-190-193.txt2.66 KBvalentin schmid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

Hrm, you can describe more about what's going wrong? I can't duplicate this currently.

Dave Reid’s picture

Status: Postponed (maintainer needs more info) » Fixed

No response in over a month, so marking as fixed.

Status: Fixed » Closed (fixed)

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

Azol’s picture

Version: 7.x-1.x-dev » 7.x-1.0-alpha2
Status: Closed (fixed) » Active

Hey, I got the same issue.
I enter URLs to redirect from and redirect to and press "Save".
I got moved immediately to correct redirect page (the one in Redirect To field) but when I go back to the URL Redirects page I can see no redirect entries at all. The list is empty.

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

I still cannot duplicate this. Can you please post the details on the redirect you were trying to save?

Azol’s picture

Redirect From = relative old path, pointing to a non-existent page, a remnant of an old site, for example:
texts/text.html
Redirect To = relative path to actual page, for example:
articles/text
When I press Save, I got redirected immediately to articles/text page (instead of staying in URL Redirects settings page).
If I move back to admin/config/search/redirect, I cannot see any entries. The redirect table in site DB is empty as well.

I do not have Global redirect or Path redirect modules installed.

Azol’s picture

Ok, I got it figured out.

You cannot create URL Redirect if the Redirect To path is a synonym OR has a synonym defined.
You won't receive any warning about that, you just got moved silently to the target web page.

Azol’s picture

Status: Postponed (maintainer needs more info) » Active

Further info:

the problem is with

// Normalize the path.
  $value = drupal_get_normal_path($value, $form_state['values']['language']);

part of the code (redirect.admin.inc, line 363). When drupal_get_normal_path got invoked, it receives a "normalized", i.e. "non-synonym" path as a $value.
Then drupal_get_normal_path itself performs a hook_url_inbound_alter(), so Redirect module receives the priority again and redirects us to the "synonym" page asap.
It means the code after line 363 is never get executed IF the path has a synonym defined.

bdunwood’s picture

sub

sylv3st3r’s picture

Can someone confirm that this patch : http://drupal.org/node/944120 resolve this issue? I haven't tried it since redirect module breaks my cron.

Azol’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Priority: Normal » Critical

No, that patch does not fix this issue.
I have tested the last dev. version with that patch incorporated, but the reason of this erroneous behaviour I have already explained in the above posts.
Actually escalating this to Critical, because the main function of the module is broken - and I think like 90% of the sites use path aliases.
I will give it a good debugging again when time allows and MAYBE I will be able to come up with the solution. Still, want to hear from Dave if he was able to reproduce this issue.

Dave Reid’s picture

Yeah I confirmed this. I'll have to disable the global redirection functionality temporarily until I can figure out a solution.

markdorison’s picture

I am experiencing this issue as well.

amanaplan’s picture

subscribing

Dave Reid’s picture

Status: Active » Fixed

I just committed the temporary disabling of global redirection until I can work out a better solution. It may have to wait until after 7.0 release.

Azol’s picture

Status: Fixed » Needs review

Please, take a quick look at this part of code (redirect.admin.inc, line 356 onwards):

function redirect_element_validate_redirect($element, &$form_state) {
//  $value = &$element['#value'];                                                         <== possibly disabling this
  _redirect_extract_url_options($element, $form_state);
  $value = &$form_state['values']['redirect'];


  // Normalize the path.
//  $value = drupal_get_normal_path($value, $form_state['values']['language']);    <<== and this

  if (!valid_url($value) && !valid_url($value, TRUE) && $value != '<front>' && $value != '') {
    form_error($element, t('The redirect path %value is not valid.', array('%value' => $value)));
  }

  return $element;
}

I have disabled these two lines of code and everything seems to be working as designed.
The reason to disable the drupal_get_normal_path call is this: you have already called _redirect_extract_url_options (line 358), which performs drupal_get_normal_path all right (line 404), so the $value (line 359) contains normalized path. When you call drupal_get_normal_path for the second time, you got redirected immediately via hook call because you are not supposed to pass normalized paths to drupal_get_normal_path function!

So I would just roll back the last change (enabling global redirect again) and change just these two lines (commenting or deleting them) to fix this issue. Works perfectly for me. At least I can not see any possible flaws in this solution.

P.S. Plus one more minor fix: line 378

  $options = & $form_state['values']["{$type}_options"];

should not contain a space between "&" and "$" symbols.

Dave Reid’s picture

Title: Can't save redirect » Re-enable global redirections
Priority: Critical » Normal

Changing scope and priority

swentel’s picture

FileSize
2.4 KB

Here's a patch that

a) does what Azol describes in #16
b) renables the global redirect functionality. I also had to change the $redirect variable to a stdClass instead of an array because that gave a lot of notices

Global redirect seems to be working fine now (so node/1 to 'a-nice-alias') and managing redirects in the admin too.

swentel’s picture

Status: Needs review » Needs work

Needs work, still have the problem of editing an existing alias, the value never gets saved, will look into it in a few moments.

swentel’s picture

FileSize
2.76 KB

Ok temporarily a patch which makes editing redirects or aliases work. Removing the code as suggested in #16 is not a solution, so that code is back in. Path.admin.inc also calls drupal_get_normal_path() in its validate function so you get redirected when editing url aliases.

I've added (a very ugly) check in redirect_url_inbound_alter() checking on arg(2) and arg(3) for 'config' and 'redirect' or 'path'. This works for now so we can edit which is good, however, this can never be RTBC.

I think we should find another way than using redirect_url_inbound_alter() because as soon as someone calls drupal_get_normal_path() you might get redirected without knowing what's going on. @Dave Reid If you have suggestions, add some comments or ping me on IRC, I'd be happy to try and test other things out for this patch.

Azol’s picture

What setup do you have? #16 worked for me so far...

swentel’s picture

Azol, try editing an existing URL alias (at admin/config/search/path), you'll be redirected too and no save.

Kiphaas7’s picture

sub

BenK’s picture

Subscribing

Docc’s picture

sub

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
3.12 KB

Patch from #20, corrected, simplified, and also avoids redirecting from cron.php, xmlrpc.php, update.php, etc.

EDIT: Also filed bug against core: #1217668: drupal_path_initialize() should not call drupal_get_normal_path() when run from cron.php.

pillarsdotnet’s picture

FileSize
1.3 KB

Additional fix to avoid php 5.3 errors from implicitly casting an array to an object.

Status: Needs review » Needs work

The last submitted patch, redirect_object.patch, failed testing.

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
3.84 KB

Trying again, with the correct patch file this time.

amanaplan’s picture

Re-rolling patch from #30, removing extra tabs/spaces from two line endings.

pillarsdotnet’s picture

Revised patch also prevents the redirect from running under drush and other CLI applications.

pillarsdotnet’s picture

Improved patch re-enables the relevant admin settings and also leverages the existing redirect_can_redirect() function.

joelstein’s picture

Status: Needs review » Needs work

I patched with #32, but got the following error when visiting /index.php:

Recoverable fatal error: Argument 1 passed to redirect_object_prepare() must be an instance of stdClass, array given, called in drupal/sites/all/modules/redirect/redirect.module on line 930 and defined in redirect_object_prepare() (line 649 of drupal/sites/all/modules/redirect/redirect.module).

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
5.85 KB

Updated patch.

Status: Needs review » Needs work

The last submitted patch, redirect-restore-global-redirect-905914-34.patch, failed testing.

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
5.86 KB

Fixed typo.

Status: Needs review » Needs work

The last submitted patch, redirect-restore-global-redirect-905914-36.patch, failed testing.

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
5.11 KB

Trying again...

pillarsdotnet’s picture

(sigh) I'll get it right eventually...

DamienMcKenna’s picture

I don't think it's quite working the way intended.

  • I've added this patch to a local install.
  • I've enabled all of the GlobalRedirect options.
  • I have a Panel page called "homepage" and the "site_frontpage" variable is set to "homepage".
  • When I visit /homepage it does not redirect to the homepage, like it would with GlobalRedirect.

Does what I'm experiencing mean that the issue needs to go back to "Needs work", or that I need to submit a new issue?

DamienMcKenna’s picture

Reviewing the configuration I realized that this was a new feature, so I added a new issue: #1255998: Option to redirect to the site root directory if the path == site_frontpage

DamienMcKenna’s picture

DaveReid, what re-engineering were you intending before re-adding this functionality?

klausi’s picture

Works for me. I'm not that experienced with this module, so I don't want to set this to RTBC. Anyone else?

grendzy’s picture

pillarsdotnet’s picture

lliss’s picture

args() is being crushed by hook_url_inbound_alter which means any code that relies on it is falling down. My fix is just to totally remove redirect_url_inbound_alter. I'm going to roll with this until something better comes along.

pillarsdotnet’s picture

args() is being crushed by hook_url_inbound_alter

Please cite a reference or otherwise support your assertion. I see nothing in the code you remove that changes the output of the arg() function.

Furthermore, you are hijacking this issue with an unrelated patch which has nothing to do with the problem and fix addressed by this issue. Please open a separate issue, instead.

Re-uploading the working patch which is currently under review.

Dave Reid’s picture

pillarsdotnet’s picture

DamienMcKenna’s picture

Anyone else running into problems with canonical URL support clashing with the pager and throwing the browser into an infinite loop?

pillarsdotnet’s picture

@DamienMcKenna -- Please describe how to reproduce this error so we can write a test case and fix it.

jenlampton’s picture

I'm not really sure what I am reviewing here, I was hoping this patch would add the functionality of global_redirect module into redirect, but after testing I think maybe that's not the case - so I'm leaving as needs review.

Results of testing: navigating to node/15 did not gently redirect me to the drupal_get_path_alias() version of the path. My page still loads and the URL says node/15. Similarly, navigating to index.php?q=node/15 also did not redirect to the clean-urls version of the path :(

For now, I'm still going to use both modules, but it would ne nice if we could get all the old D6 redirect modules into Redirect :)

DamienMcKenna’s picture

@pillarsdotnet: I'm using a Panels node view for the content type, on the node I have a view with a pager, clicking on any page in the pages list should go to e.g. /mypage/page/1/0 but instead is redirected back to /mypage. I haven't dug into it too much, but disabling the "redirect canonical URL" option fixes it.

DamienMcKenna’s picture

@jenlampton: Did you enable the "redirect canonical URL" option? What options did you enable in the Redirect settings page?

jenlampton’s picture

Status: Needs review » Needs work

@DamienMcKenna I am running the dev snapshot from Dec 2, and *thought* I had applied this patch. It appears 'git apply' didn't work at all for me, and after you asked me if I'd turned on canonical redirection, I realised that I'd never even seen that option! :) a patch -p1 did the trick for me this time, but bad news...

With the following settings, I get this error when visiting index.php?q=node/15:

Recoverable fatal error: Argument 1 passed to redirect_redirect() must be an instance of stdClass, array given, called in .../sites/all/modules/contrib/redirect/redirect.module on line 287 and defined in redirect_redirect() (line 916 of .../sites/all/modules/contrib/redirect/redirect.module).

Redirect from paths like index.php and /node to the root directory. (Checked)
Redirect from non-clean URLs to clean URLs. (Checked)
Redirect from non-canonical URLs to the canonical URLs. (Checked)
Remove trailing slashes from paths. (Checked)
Allow redirections on admin paths. (Un-Checked)

rickvug’s picture

The last patch was not applying for me. Attached is a re-roll. I've yet to test the actual workings of the patch.

jenlampton’s picture

Status: Needs work » Needs review

Working on the patch from #56 (which applies cleanly) :)

- changing pathauto "patterns" and re-saving node with pathautp checkbox checked redirects.
- changing node title and re-saving node redirects.
- visiting the Drupal system path for the node (node/1) redirects.
- visting non-clean url (?q=node/1) redirects.
- visiting actual full url (index.php?q=node/1) also redirects
- visiting any one of the paths above with a trailing slash, redirects.
- visiting the Drupal system path with a query string (node/1?foo=bar)redirects, retaining the query string.

Anything else I should be testing? test bot?

DamienMcKenna’s picture

@jenlampton: did you try a pager? E.g. attach a view to a page and have sufficient records in the view that it makes a pager display, the URLs will be in the form /clean/url/page/0/1 but they all redirect back to /clean/url.

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

A page-view pager seems to be in the format pager-test?page=1. A block-view pager also adds a query string articles/test-article?page=4.
... still not sure where the redirects come in for views.

But Test bot likes it :)

jantoine’s picture

Status: Reviewed & tested by the community » Needs review

#1255998: Option to redirect to the site root directory if the path == site_frontpage

Given that the issue above has been marked a duplicate of this issue, I imagine that after applying this patch, the path I have specified as my front page should be redirected to the to the sites base URL, but this is not the case.

Steps to reproduce:

  1. Create a view with a page display with the path "front"
  2. Set the front page path to "front"
  3. BUG: example.com/front is not redirected to example.com.
batigol’s picture

So in other words with this patch Redirect module should be replace for Global Redirect module ?

jenlampton’s picture

Status: Needs review » Needs work

I'm running into the same problem with front page, but all other redirections are working. Changing status.

@batigol, yes :)

fasdalf@fasdalf.ru’s picture

Status: Needs work » Needs review
FileSize
6.64 KB

I have added global home page redirect for both clean and "dirty" URLs for AntoineSolutions and myself.
It's reworked patch from #56 and it should do all things from #57 and a bit more
* example.com/index.php?foo=bar&q=node/123 -> example.com/node/123?foo=bar
* example.com/index.php?q=node/123&foo=bar -> example.com/node/123?foo=bar
* example.com/index.ph?q=node -> example.com/ (if "node" is home page)
* example.com/node -> example.com/

Status: Needs review » Needs work

The last submitted patch, redirect-frontpage.patch, failed testing.

fasdalf@fasdalf.ru’s picture

Status: Needs work » Needs review
FileSize
6.6 KB

patch fixed (i hope)

pwiniacki’s picture

I don't use front page on my site so I can't test it. But it seems to work fine on my friend page.

However do I need to install Global Redirect in addition to this module ? Does redirect works the same way or there are some differences ?

pillarsdotnet’s picture

@pwinlacki -- With the patch, the Redirect module should do everything that Global Redirect does, and more.

batigol’s picture

Pillarsdotnet thank you for clearing this out. I can't wait till beta5/rc1 release !

fasdalf@fasdalf.ru’s picture

Status: Needs review » Reviewed & tested by the community

I would note one specific thing: You should not set alias (welcome) for front-page path (node/1). If you do this redirect will send you to front page's alias (http://example.com/welcome) if you type site URL (http://example.com)
Is this a bug to resolve?

pillarsdotnet’s picture

Status: Reviewed & tested by the community » Needs review

@fasdalf@fasdalf.ru -- You should not RTBC your own patch. Also,

+  $is_query = (strpos($request_uri, '?q=') !== FALSE) || (strpos($request_uri, '&q=') !== FALSE);

Yuck! Isn't there anything in the Drupal API to accomplish this?

fasdalf@fasdalf.ru’s picture

FileSize
9.12 KB

New patch checks if requested page is front and skips redirect to alias.

Status: Needs review » Needs work

The last submitted patch, global.patch, failed testing.

fasdalf@fasdalf.ru’s picture

Status: Needs work » Needs review
FileSize
8.54 KB

Patch rebuilt

Status: Needs review » Needs work

The last submitted patch, global.patch, failed testing.

fasdalf@fasdalf.ru’s picture

Status: Needs work » Needs review
FileSize
8.54 KB

Status: Needs review » Needs work

The last submitted patch, global.patch, failed testing.

fasdalf@fasdalf.ru’s picture

FileSize
42.31 KB

Sorry. Can't figure out what it's don't like. Attach is new version of home/front page feature.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
6.05 KB

After I figured out what you changed in the patch file, I applied the same changes to my own copy of redirect. I do not see the site redirecting from 'welcome' to the front page with no path (to use your example).

Trying a new approach.

Status: Needs review » Needs work

The last submitted patch, reenable_global_redirections-905914-78.patch, failed testing.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
6.82 KB

Hm, I'm not sure why that test failed.

I disabled cleanURLs and un-checked the cleanURL redirect checkbox, and my site redirects from ?q=redirect to ?q=node just fine.

Rerolled with one other minor bug fixed, but if the test needs to be rewritten I may need some help with that.

Status: Needs review » Needs work

The last submitted patch, redirections_with_frontpage-905914-80.patch, failed testing.

valor’s picture

Status: Needs work » Needs review
FileSize
6.84 KB

Status: Needs review » Needs work

The last submitted patch, redirect-global-redirection-905914-82.patch, failed testing.

fasdalf@fasdalf.ru’s picture

IMHO there is a problem with this code

+  // Redirect to front page.
+  if (variable_get('redirect_global_home', TRUE) && drupal_is_front_page()) {
+    $redirect_global = TRUE;
+    $request_uri = '';

It will make endless redirect. I believe it should be like this:

+  // Redirect to front page.
+  if (variable_get('redirect_global_home', TRUE) && drupal_is_front_page() && isset{$_GET['q']}) {
+    $redirect_global = TRUE;
+    $request_uri = '';
DamienMcKenna’s picture

@fasdalf: I believe you meant:

+  if (variable_get('redirect_global_home', TRUE) && drupal_is_front_page() && isset($_GET['q'])) {
pillarsdotnet’s picture

klaasvw’s picture

This is slightly related. The stub for implementing global redirect functionality is causing problems with some modules: #1463010: Entity_load during url_inbound_alter is incompatible with text fields

jenlampton’s picture

in response to #85,
isset($_GET['q'])) doesn't prevent the infinite redirect on the home page either. Would love suggestions as to how to get that working.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
7.13 KB

Okay, here I tried to determine if we were on the front page already by comparing $_SERVER['REQUEST_URI'] to base_path().
Also trying a new approach, this time with the redirect firing in hook_url_inbound_alter instead of in hook_init.

Status: Needs review » Needs work

The last submitted patch, enable_global_redirections_with_frontpage-905914-88.patch, failed testing.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
6.94 KB

and one more time sans dsm.
dunno why tests are failing, but maybe someone else can help with that?

Status: Needs review » Needs work

The last submitted patch, enable_global_redirections_with_frontpage-905914-91.patch, failed testing.

Alan D.’s picture

Please note that calling entity_load() can break things if done before menu_get_custom_theme().

See #1370964: Redirect interferes with hook_custom_theme for details.

pfournier’s picture

This patch results in infinite redirections when Persistent URL (purl) module is installed. Investigating.

pfournier’s picture

Doing a redirect from hook_url_inbound_alter is not right; this hook is called from drupal_get_normal_path(), and callers of drupal_get_normal_path() certainly do not expect a redirect to be done.

IMHO all redirects should be done in hook_init().

barraponto’s picture

Status: Needs work » Needs review
Issue tags: -D7 stable release blocker

Status: Needs review » Needs work
Issue tags: +D7 stable release blocker

The last submitted patch, enable_global_redirections_with_frontpage-905914-91.patch, failed testing.

barraponto’s picture

Status: Needs work » Needs review
FileSize
9.3 KB

Ok, so the errors are because the test expects the user to be redirected to the actual redirect url, but it might (should) redirect to the frontpage (no internal path) if the redirect url is actually the frontpage. So I guess we have to fix the test.

There's some logic already available at redirect_url_inbou'nd_alter checking for the redirect_global_home variable. And I don't think it should default to TRUE, since that wasn't the behaviour before. I'm just changing that and hoping it fixes the tests until we improve them.

DamienMcKenna’s picture

pillarsdotnet’s picture

Re-rolled against current 7.x-1.x checkout.

Status: Needs review » Needs work

The last submitted patch, 905914-redirect-reenable-global-redirections-100.patch, failed testing.

pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
7.28 KB

Missed a closing brace; sorry.

Status: Needs review » Needs work

The last submitted patch, 905914-redirect-reenable-global-redirections-102.patch, failed testing.

pillarsdotnet’s picture

Not sure whether the static is supposed to store a single redirect or an array as returned from (e.g.) redirect_load_by_source().

Going with the latter for now...

pillarsdotnet’s picture

Status: Needs work » Needs review
jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

Patch works great for me!

jenlampton’s picture

Removed whitespace errors too.

wizonesolutions’s picture

Can someone update the issue summary? The patch is RTBC and passing tests, but I don't remember what it's supposed to do. At a camp this weekend so might have time to commit this.

barraponto’s picture

Tagging.

greggles’s picture

Title: Re-enable global redirections » Merge global redirect functions into Redirect module
Issue tags: -Needs issue summary update

I tried to update the issue summary based on reading many of the comments here (and skimming some). I didn't review the code.

greggles’s picture

reverting unintentional de-tagging...

jenlampton’s picture

Update: Patch still applies cleanly, and still works :)

wiifm’s picture

Status: Reviewed & tested by the community » Needs work

Having got rid of the module globalredirect recently and added redirect, I did miss the functionality that globalredirect provided around sending 'node/1234' => path_alias.

I applied this patch to 7.x-1.x-dev, and it mostly seemed fine. The only major issue is that the homepage no longer is accessible on '/', as it redirects to 'home' (the path alias for node/1). This some how causes panels selection criteria to break (page is the site front page).

Obviously there is some work around the homepage that needs to be completed before this is ready to go.

I started altering the patch, and then worked out it would probably be easier if I merely implemented hook_init() myself and do the redirect for node/1234 => path_alias

pillarsdotnet’s picture

One of the reasons for implementing global redirect is to avoid having two urls point to the same content. If the example.com front page is set to home which is an alias for node/1 then exactly one of the two rules should be enforced:

  1. Visiting http://example.com/node/1 or http://example.com/
    ... should redirect to http://example.com/home
  2. Visiting http://example.com/node/1 or http://example.com/home
    ... should redirect to http://example.com/

Do your panels selection criteria only break when rule #1 is active, or do they also break when visiting http://example.com/node/1 or http://example.com/home directly? If the latter, then I'd say you have identified a bug in panels, not in the redirect module.

pillarsdotnet’s picture

wiifm’s picture

When I had the globalredirect module enabled, node/1 would go to '/' which was perfect as it was the homepage.

With this patch applied, this is what happened:

1) Visit '/', redirected to '/home', panels selection criteria fail
2) Visit '/node/1'. redirected to '/home', panels selection criteria fail

I don't know if it makes any difference, but the site I am working on is multilingual as well (so there is indeed two site_frontpage)

barraponto’s picture

@pillarsdotnet i think the expected result is option #2: both node/1 and /home should redirect to /

I think that's what @wiifm says in #116 and that's what I'd expect as well. I think (from #98) that there's a variable (redirect_global_home) and a test for that.

jenlampton’s picture

I'm putting this patch on yet another site, here is what I did:

1) enable redirect module (dev version, with patch applied)
2) go to redirect settings page to enable 'global redirect' functionalty
3) enable the setting "Redirect from paths like index.php and /node to the root directory."

And here are my tests:

Navigate to the home page '/' - expect no redirection. Works as expected.
Navigate to my panel for use on the front page '/frontpage' - expect redirect to '/' - Works as expected.

jenlampton’s picture

Status: Needs work » Needs review

changing status, I have a feeling you just forgot to check the box to turn on the home page redirect feature. I can't get it to misbehave. :)

Alan D.’s picture

Reroll.

Minor change

+    'redirect_global_home' => FALSE,
+    'redirect_global_home' => 0,

and

+    '#default_value' => variable_get('redirect_global_home', FALSE),
+    '#default_value' => variable_get('redirect_global_home', 0),
Alan D.’s picture

Another style error :(

However, this doesn't completely work as expected for pages with aliases.

Enable Path & Redirect
Create a node and set alias to home
Check redirect_global_home
Set Site Information Default front page to home

node/1 redirects to home

Set Site Information Default front page to node/1

node/1 redirects to home

A quick look shows that on /home, $_GET['q'] is set to the alias when drupal_is_front_page() is called.

No time to investigate further, but the quickest workaround I saw was to remove the alias, and to use Page manager / Panels to embed the node on a custom page with the URL home and setting this as the default front page in the site Information settings.

greggles’s picture

I notice that this patch includes new functionality, but doesn't include any tests.

The discussion in #117/119 makes it clear that some tests could be helpful to be more confident that the functionality works as expected.

Alan D.’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Changing status as per Greg's comment and issue related to path aliases noted in #116 & #121.

ericras’s picture

The functionality I'm looking for is the "Deslash" setting from Global Redirect that 301's a request for about-us/ to about-us

I've applied #121 to latest dev of Redirect and it looks like the setting redirect_global_deslash (Remove trailing slashes from paths) doesn't Deslash anything and the setting isn't being referenced anywhere.

mrweiner’s picture

The work being done here is great, and is moving in the right direction. Although it does what it is supposed to, I've discovered a conflict that it produces. I am using the Video Embed Field module to display youtube videos in a colorbox on my site. With the latest version of the patch applied, a $variables array created by Video Embed Field is not populated correctly when using a colorbox to load the video. As a result, the video does not display. I originally opened an issue over there at #1908058: $variables array not being built correctly when using colorbox..

Not sure where the conflict is exactly, but I figured I should point it out. Let me know if you need more clarification.

acbramley’s picture

Only thing holding me back from making the jump to this module is the entity id url -> alias redirection. IMO that is one of the best features of globalredirect, but I need my clients to have an admin interface for redirects. Any ideas of when this feature will come in?

Gastonia’s picture

After reading this post as well as several others in the queues about the differences between Global Redirect and Redirect, I too am confused as to a few things. First, Obviously we want the functionality of cleaning up duplicate content that Global Redirect provided.

Also, in Pathauto config screen under settings recommends using the "Redirect" module when "leaving old aliases intact when generating new aliases." Which, is of course what I want as I am about to do a massive url structure rewrite and want redirects from the old aliases.

So, Can I use both Global Redirect and Redirect despite the effort of merging the former into the latter? Are their conflicts?

Secondly, as of the patch and few comments above, this still needs testing and people are finding minor bugs.

So then, what is the stable solution? Do / Can I use both Global Redirect and Redirect together? Or is the merging functionality stable enough that it has made GR obsolete, and I can happily get rid of it and use just Redirect as the complete solution?

Thanks!

acbramley’s picture

I'm currently running an older dev release of Redirect that contains the alias redirecting from the system paths which I needed. I disabled globalredirect and enabled that and it works a treat. I don't think it'd be a good idea to run the 2 side by side though.

ericras’s picture

Here's where I'm at working on #121:

* Got Deslash (Remove trailing slashes from paths) working.
New features:
* redirect_global_index setting to remove 'index.php' from non-front paths.
* redirect_global_canonical_front setting to indicate if you want the front page to redirect to its canonical URL. I found that with the existing redirect_global_canonical setting, a request for the root "/" would redirect to "/welcome-to-my-site" because that is the front page canonical URL. That's undesired behavior in most cases.

I've tested this with pathauto and subpathauto with success. Obviously it still lacks test cases.

The big structure question I have is should this global behavior reside in redirect_url_inbound_alter() or redirect_init()? I basically left it as it was - calls to redirect_redirect() split between the two. I'm guessing redirect_url_inbound_alter() should only contain calls to redirect_set_current_redirect() and no calls to redirect_redirect() so that other modules can still execute their hook_url_inbound_alter(). Then redirect_init() can use redirect_get_current_redirect() and do the redirect.

ericras’s picture

Here is #129 + Add Slash functionality for use with the Trailing Slash module to enforce trailing slashes.

Juan C’s picture

I used #130 for a week, works for me so far. Thanks.

greggles’s picture

Status: Needs work » Needs review

Does this need anything other than tests?

unleet’s picture

Status: Needs work » Needs review

Patch #130 is giving me redirect loops with the "Redirect from non-canonical URLs to the canonical URLs" option turned on.

# curl -I http://dev.papercutmag.com/articles/2013/06/24/david-sheldrick
HTTP/1.1 301 Moved Permanently
Date: Thu, 27 Jun 2013 04:50:59 GMT
Server: Apache/2.2.24 (Amazon)
X-Powered-By: PHP/5.3.25
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified: Thu, 27 Jun 2013 04:50:59 +0000
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1372308659"
Location: http://dev.papercutmag.com/articles/2013/06/24/david-sheldrick
Connection: close
Content-Type: text/html; charset=UTF-8
unleet’s picture

Status: Needs review » Needs work
Corwin’s picture

Status: Needs review » Needs work

How do you redirect from sub.domain.com to domain.com/sub ?

jenlampton’s picture

I'm also getting the following error when I have a view on my home page with a pager, and I click any of the pager links:

User warning: Infinite redirect loop prevented. in redirect_redirect() (line 1040 of drupal-7/sites/all/modules/contrib/redirect/redirect.module).

I don't have any redirects set up for my home page, but it is a panel that's set up at /front. If I UNcheck the box for Redirect alternative front page URLs to the root directory, then everything behaves properly.

candelas’s picture

any news on redirects? thanks for your hard work :)

batigol’s picture

I guess nobody is working at it at the moment. All focus is on Drupal 8.

acbramley’s picture

@Corwin I believe that sub domain redirects need to be done at a webserver level rather than through Drupal.

PlayfulWolf’s picture

@acbramley there is always the case when webmaster has limited access to webserver configuration - so it may be an option in some Drupal module, but now I am thinking, if it is even possible...

j0rd’s picture

What features does redirect currently have, in the stable release which are from global redirect, which were not included previously in the D6 path_redirect module?

For me, the "basic" functionality of global_redirect was two things, removing trailing slash and redirecting node/123 to path alias. It appears the stable version of redirect currently does neither of these.

Because of this, I would recommend changing the description of this project because it's confusing for an experienced user of Drupal, who have used the previous modules this module claims to replace. For inexperienced users, I assume it would be worse.

I would recommend stating what features the stable version provides (or dev) from Global Redirect, and which features it does not implement. Then I would recommend linking to this patch and including what features this patch includes from Global Redirect, which work (and link to a specific patch version).

Perhaps this would get more people in here testing and moving this forward. This patch issue has been ongoing for 3 years now.

--

This is just my experience from reading over the description of this module, thinking to myself, awesome I don't need global redirect...only to find out I still do.

colan’s picture

Priority: Normal » Major

Moving this up in priority, just in case it helps. ;)

subhojit777’s picture

#121 and #129 patches not working. I am getting infinite loop messages in certain pages.

batigol’s picture

I have tested it again, and there are still problems. Installing DA and i18n give me loops almost all the time but i guess integration with those module will be add later on.

batigol’s picture

Issue summary: View changes

attempting to update the summary

ericras’s picture

Issue summary: View changes
FileSize
12.79 KB

Here's an update that should correct the redirect issue described in #136, #143, etc. I was not accounting for query strings.

The big outstanding thing is tests.

I've been using this in production successfully since March. The one minor bump in the road for me has been using it on a site that is behind an Apache ProxyPass setup; redirect_can_redirect() returns false since $_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php'

oadaeh’s picture

Status: Needs work » Needs review

Setting to Needs review so the testbot will test the most recent patch.

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

I'm marking this issue RTBC since the patch in #145 is working great for me. If tests are needed before this can be committed feel free to push back, but I'd love to get this in sooner rather than later. Almost all my sites are using one version of this patch or another ;)

ezeedub’s picture

Status: Reviewed & tested by the community » Needs work

I just ran into an infinite redirect loop on a multilingual site for the case where the redirect_global_home = 1, and then visiting http://example.com/en.

I believe globalredirect used to deal with this (as well as redirecting http://example.com to http://example.com/en). I'm sorry I don't have time to provide a patch right now, but am currently accounting for this in hook_redirect_alter().

if ((current_path() == variable_get('site_frontpage')) && (in_array(request_path(), array_keys(language_list())))) {
    $redirect->redirect = FALSE;
}
kalabro’s picture

@ezeedub, have you applied patch from this issue first #1796596: Fix and prevent circular redirects?

kalabro’s picture

Status: Needs work » Reviewed & tested by the community

@ezeedub, I restore this issue status.

candelas’s picture

kalabro, do you recomend to apply patch #146 on https://drupal.org/comment/8506117#comment-8506117 and then this. there is no conflict? sorry, i am learning about patches and if they run on the same dev, won't they interference? thanks :)

kalabro’s picture

@candelas, I've applied both on my local environment and after testing deployed to live website.

candelas’s picture

thanks kalabro. I have installed it and until know it looks ok. i will report if i have any problem :)

ezeedub’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
13.43 KB
1.36 KB

@kalabro You are right, I had not applied that other patch. I was confused about whether this issue superseded that one or not. Applying fixes the issue I mentioned in #148.

However, I got to that issue via another. Using globalredirect, paths such as /user were redirecting to /en/user. I switched to redirect though because of the infinite looping issue. Which brought me here (in addition to the other issue you just referenced).

So, long story short... I've tracked what I think we really need, and that is to re-add the globalredirect functionality of prepending the language prefix.

ezeedub’s picture

Here's another try which handles language prefixes better.

Status: Needs review » Needs work

The last submitted patch, 155: redirect-global-905914-155.patch, failed testing.

ezeedub’s picture

Status: Needs work » Needs review
FileSize
13.74 KB
2.21 KB

Argh, add new language prefix to redirect_variables()...

Status: Needs review » Needs work

The last submitted patch, 157: redirect-global-905914-157.patch, failed testing.

ezeedub’s picture

The last submitted patch, 157: redirect-global-905914-157.patch, failed testing.

ezeedub’s picture

Status: Needs work » Needs review
FileSize
13.87 KB
2.34 KB

Add test for locale in redirect_redirect()...

jasonlttl’s picture

Status: Needs review » Needs work

I think there may be a problem in #161 with language.inc being conditionally loaded independent of whether or not the locale module is enabled.

Specifically, I'm getting...
Fatal error: Call to undefined function language_url_split_prefix() in [snip]/redirect/redirect.module on line 1125

I actually have a few other patches applied so for me that's here.

/**
 * Redirect callback; perform an URL redirect.
 */
function redirect_goto($redirect) {
  $redirect->redirect_options['absolute'] = TRUE;
  // Prevent a path like 'index.php?q=node/1' from redirecting to '?q=path-alias'
  // if canonical redirection is disabled. This will make url() treat 'node/1'
  // as if it is already an alias and prevent a drupal_get_path_alias() lookup.
  if (!variable_get('redirect_global_canonical', 0)) {
    $redirect->redirect_options['alias'] = TRUE;
  }
  if (module_exists('locale')) {
    // Peel off language prefix if already there.
    list($language, $raw_path) = language_url_split_prefix($redirect->redirect, language_list()); # <------ Error is here

There's a long issue in pathologic regarding a similar problem.
https://drupal.org/node/1848554

Their solution was to do this...

 // Let's see if we can split off a language prefix from the path.
 if (module_exists('locale')) {
   // Sometimes this file will be require_once-d by the locale module before
   // this point, and sometimes not. We require_once it ourselves to be sure.
   require_once DRUPAL_ROOT . '/includes/language.inc';
   list($language_obj, $path) = language_url_split_prefix($parts['path'], language_list());

If I look at locale.module, I see that file being included on demand a lot so it seems like module_exists is probably not quite enough.

grep -irn language.inc locale.module
locale.module:509:        require_once DRUPAL_ROOT . '/includes/language.inc';
locale.module:639:  include_once DRUPAL_ROOT . '/includes/language.inc';
locale.module:1019:  include_once DRUPAL_ROOT . '/includes/language.inc';
locale.module:1069:      include_once DRUPAL_ROOT . '/includes/language.inc';
jasonlttl’s picture

Attached is a patch that adds a require for the language.inc

jasonlttl’s picture

Status: Needs work » Needs review
shahinam’s picture

Status: Needs review » Needs work

There is redirect loop for "Redirect from non-canonical URLs to the canonical URLs"
Clean URLS are also getting redirected and enters redirect loop - which is finally detected and stopped
inside redirect_redirect()

Disabling "Redirect from non-canonical URLs to the canonical URLs" from settings,
"Redirect from non-clean URLs to clean URLs" then has no effect and does not redirect no-clean to clean.

beeradb’s picture

FileSize
14.58 KB

Attached patch is based on #161 and adds whitelist support to the language redirect option.

Honza Pobořil’s picture

It is quite hard to understand this issue status. What blocks commiting of finished features? What features are not finished yet?

I think this information should be in the issue summary for issues long like this.

jenlampton’s picture

Status: Needs work » Needs review

changing status for testbot.

Status: Needs review » Needs work

The last submitted patch, 166: 905914-166-redirect-global.patch, failed testing.

jessehs’s picture

Status: Needs work » Needs review
FileSize
14.6 KB

This is a reroll of 166 to apply to 7.x-1.x-dev. The only difference is the removal of the one failing hunk. As far as I can tell, this was fixed a different way in dev.

@@ -979,7 +1042,7 @@ function redirect_purge_inactive_redirects(array $types = array('redirect'), $in
  *
  * @ingroup redirect_api
  */
-function redirect_redirect($redirect = NULL) {
+function redirect_redirect(stdClass $redirect = NULL) {
   // First check if we're in an infinite loop.
   $session_id = session_id();
   if (flood_is_allowed('redirection', 5, 15, $session_id ? $session_id : NULL)) {
jessehs’s picture

Same as patch in 170, except a variable was given the wrong default value (causing weirdness for front page paths). See interdiff.

Now, given the following 3 nodes with the following aliases:

node/1 => foo
node/2 => bar
node/3 => home (set as site home page)

Enable the module. Visiting all paths now redirect to their aliases.
Edit: the 'node/3' path now redirects to '/' (home).

When the "Redirect the front page to its canonical URL" is checked, www.example.com/node/3 is directed to "home" AND www.example.com/ is also directed to "home".

B-Prod’s picture

@jessehs: your patch does not take care of #162, so it does not work on multilingual sites.

colan’s picture

Status: Needs review » Needs work

Changing status based on #172.

vadym.kononenko’s picture

Added #162 require_once() to #171

barraponto’s picture

Status: Needs work » Needs review
Dave Reid’s picture

DamienMcKenna’s picture

Issue summary: View changes

Fixed a small typo in the issue summary, an open LI was missing.

krisahil’s picture

Re-rolled patch from #174 against latest 7.x-1.x (7.x-1.0-rc1+13-dev).

deanflory’s picture

Patch #178 FAILS when applied to the latest dev (2015-Jan-05).

patching file redirect.admin.inc
patching file redirect.module
Hunk #6 FAILED at 1215.
1 out of 7 hunks FAILED -- saving rejects to file redirect.module.rej

hass’s picture

Status: Needs review » Needs work
greggles’s picture

Status: Needs work » Needs review

Applied fine to the tip of the 7.x-1.x branch for me using either "git apply merge-globalredirect--905914-178.patch" or "patch -p1 < merge-globalredirect--905914-178.patch"

deanflory’s picture

Tried again and got the same error with Mac OS Terminal with these:

patch < merge-globalredirect--905914-178.patch
AND
patch -p1 < merge-globalredirect--905914-178.patch

colan’s picture

Both "git apply" and "patch" commands worked for me, latest 7.x-1.x.

greggles’s picture

@deanflory I mentioned that it applies cleanly to the tip of 7.x-1.x branch. If the version you have is something else it might not apply. For example, I get 2 hunk fails on 7.x-1.0-rc1. Ping me (greggles) on irc if you want to discuss applying patches more (probably other people would be happy to help too, especially if your goal in applying it is to provide a patch review).

deanflory’s picture

Just reporting what I'm experiencing with the patch in #178 and the latest dev as mentioned in #179:
Last updated: January 5, 2015 - 16:18
Last packaged version: 7.x-1.0-rc1+13-dev

If it's somehow just me then let's not drown this issue with whatever oddity I'm experiencing. "Move along" :)

vadym.kononenko’s picture

I can not apply patch #178 too. This part of patch was'n applied.

--- redirect.module
+++ redirect.module
@@ -1215,7 +1291,7 @@
       // If this is a command line request (Drush, etc), skip processing.
       $can_redirect = FALSE;
     }
-    elseif ((variable_get('maintenance_mode', 0) || defined('MAINTENANCE_MODE')) && !user_access('access site in maintenance mode')) {
+    elseif (variable_get('maintenance_mode', 0) || defined('MAINTENANCE_MODE')) {
       // Do not redirect in offline or maintenance mode.
       $can_redirect = FALSE;
     }

I see it is applied to module already. So, I've just captured patch after #178 was applied without part above.

Majdi’s picture

I test the patch in one of the site I develop , it has around 3k visitor/day with 2 languages and we just migrate from the old system, so I redirect many urls , and the module play nice with the patch, thanks

pwiniacki’s picture

@Majdi did you use latest #186 patch?

Majdi’s picture

@pwiniacki yes patch #186

jantoine’s picture

Using the patch at #186, when locale is enabled using language path prefixes, viewing the home page in any language other than the default language causes a redirect loop. In redirect_url_inbound_alter(), when redirecting the front page to the root level (starting at line 252 of a patched redirect.module file), there is no check that we are at the root level for a language other than the default. I fixed this by adding a comparison between the current language's prefix and the request path.

Updated patch and interdiff attached.

Manuel Garcia’s picture

+++ b/redirect.module
@@ -251,7 +253,8 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) {
+      && "/$language->prefix" != $request_path) {

Haven't tested but should this rather be base_path() . $language->prefix != $request_path oslt?

valentin schmid’s picture

Patch #190 is giving me redirect loops if the option "Redirect from non-canonical URLs to the canonical URLs." is selected. Here's a new patch, which fixes this issue.
It also fixes the comment #191.

valentin schmid’s picture

The function redirect_load_by_source must return "The first matched URL redirect object", not a list of objects.
Patch #193 fixes this issue. It is now also possible to apply patches from issue #1796596.

The last submitted patch, 193: redirect-merge-global-redirect-905914-193.patch, failed testing.

valentin schmid’s picture

D'oh! Forget to change a line in patch #193. Hope this one is better!

ramotowski’s picture

I can confirm that the code from the last patch #195 works great.

Dave Reid’s picture

kelutrab11’s picture

So this patch makes redirect module (besides some of it's other functions) work as global redirect? I don't need to install global redirect then?

Majdi’s picture

yes no need for global redirect

pwiniacki’s picture

#195 is working very good. Great work!

EDIT: also applied to rc-3 - working good.

dillix’s picture

Status: Needs review » Reviewed & tested by the community

#195 works great! Please commit this.

miro_dietiker’s picture

Dave Reid, you proposed to merge global redirect functionality into redirect module?
We hesitated with going forward with adding this functionality to 8.x branch because this issue was stuck for years.

Should we go ahead and merge our 8.x global redirect functionality into redirect module port and thus deprecate the 8.x port of global redirect? It would be a good moment to do so before Drupal 8 is released.

kelutrab11’s picture

@miro_dietiker +1 for the idea.

Majdi’s picture

Just one more point , globalredirect has this option "Case Sensitive URL Checking" I think this is missing in this patch

Dave Reid’s picture

Yes, this is still planned for the 7.x module, so I would say it should go in 8.x. I'm just a bit more focused on trying to get everyone a stable 1.0 release they deserve in Drupal 7 now, before I go back to features again.

dillix’s picture

Dave Reid, will you make next RC with this patch?

DamienMcKenna’s picture

To anyone who didn't quite understand Dave's comment #205, what he meant was that he's not going to add more features to v7.x-1.0, he's focusing on bug fixes so that the final 1.0 release is stable. However, once 1.0 is out he'd consider adding new features, including this one.

That said, Dave, you added the "D7 stable release blocker" tag to this back in comment #48, if you no longer feel that's appropriate could you please remove the tag to help avoid confusion, because you've basically indicated for four years this would be included? Thanks.

dillix’s picture

DamienMcKenna, Dave added D7 stable release blocker tag, so I confused...

dillix’s picture

Also as I can see this is last bug with this tag, which not fixed yet:
https://www.drupal.org/project/issues/search?text=&projects=Redirect&ass...

DamienMcKenna’s picture

@dillix: I know, I pointed out the discrepancy in my comment #207. Dave's at NYC Camp, lets see what he says when he gets to somewhere with wifi and a power source.

dillix’s picture

If this patch will be committed it would be great, so we can drop Global Redirect!

rikvd’s picture

the latest patch does not play nicely with i18n, it checks against the current set language.

node/1 alias: foo language: en

if the user goes to node/1, with default language nl isn't redirected to en/foo

edit: found an article, to get the desired result, maybe it's an good idea to intergrate the snippet in the patch

https://www.drupal.org/node/1280468#comment-6229920

pwiniacki’s picture

@rikvd nice catch. Confirmed.

dillix’s picture

@rikvd, @pwiniacki may be we should commit this & open new issue for compatibility with i18n?

Sebastien M.’s picture

Hi agree with @dillix.
This fix is quite stable and so useful. It should be interesting to merge it now and go further with a new issue.

pwiniacki’s picture

@dillix ok, cause this patch is working fine with basic page functionality. However more i18n and DA test are welcome so 1.0 release can be bug free and used in more complex sites.

DamienMcKenna’s picture

Has anyone tried the Multilink Redirect submodule from Multilink to resolve the problem with i18n redirects?

Dave Reid’s picture

My concern right now is stability of the 7.x-1.x branch and not adding new features before the 7.x-1.0 release. I *do very much* want to get this in so I'm going to open a new 7.x-2.x branch which addresses some major architectural changes (moving the redirect counting to a separate sub-module) as well as this issue as a first priority.

Dave Reid’s picture

  • Dave Reid committed 9299ca4 on 7.x-2.x
    #905914 by Dave Reid: Disable global redirects when using...
  • Dave Reid committed e39a31d on 7.x-2.x
    #905914 by Dave Reid: Disable global redirects when using hook_init().
    
DamienMcKenna’s picture

Thanks for the update, Dave.

Dave Reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
jenlampton’s picture

Patch in 195 applies cleanly to the 2.x branch as it is now.

Xrobak’s picture

Is it possible to do an ability "Case Sensitive URL Checking" (If enabled, the module will compare the current URL to the alias stored in the system. If there are any differences in case then the user will be redirected to the correct URL.) like in Global Redirect?

  • Dave Reid committed 9299ca4 on 8.x-1.x
    #905914 by Dave Reid: Disable global redirects when using...
  • Dave Reid committed e39a31d on 8.x-1.x
    #905914 by Dave Reid: Disable global redirects when using hook_init().
    
NWOM’s picture

I tried applying #195 to 7.x-2.x-dev, but it seems to not apply cleanly. Anyone else having this issue?

Checking patch redirect.admin.inc...
Hunk #1 succeeded at 670 (offset 30 lines).
Hunk #2 succeeded at 754 (offset 30 lines).
Checking patch redirect.module...
Hunk #4 succeeded at 807 (offset 42 lines).
Hunk #5 succeeded at 1189 (offset 117 lines).
error: while searching for:
    'redirect_page_cache' => 0,
    'redirect_purge_inactive' => 0,
    'redirect_global_home' => 1,
    'redirect_global_clean' => 1,
    'redirect_global_canonical' => 1,
    'redirect_global_admin_paths' => 0,
  );
}


error: patch failed: redirect.module:1287
error: redirect.module: patch does not apply
git apply failed; falling back to 'patch' tool                                                                                                      [warning]
patching file redirect.admin.inc
Hunk #1 succeeded at 670 (offset 30 lines).
Hunk #2 succeeded at 754 (offset 30 lines).
patching file redirect.module
Hunk #4 succeeded at 807 (offset 42 lines).
Hunk #5 succeeded at 1189 (offset 117 lines).
Hunk #6 succeeded at 1486 with fuzz 2 (offset 118 lines).
No syntax errors detected in redirect.admin.inc
No syntax errors detected in redirect.module

Edit: Nevermind, it appears falling back to the patch tool allows it to apply cleanly.

DamienMcKenna’s picture

NWOM’s picture

#227 applied cleanly with git. Thank you!

kclarkson’s picture

Has anyone updated the maintainers of Global Redirect?

Also is all of this functionality going to be merged for the 8.x version?

delacosta456’s picture

Hi

doest it mean that with this patch we do not need to install any more the Golbal redirect module?

thanks

DamienMcKenna’s picture

@delacosta456: Yes, that is the plan :)

delacosta456’s picture

ok thanks

naveenvalecha’s picture

Let;s get this dang in.

glass.dimly’s picture

Would love to see this rolled into the 2x dev version. It's not, right?

DamienMcKenna’s picture

It'd also be good to get this functionality into the D8 branch.

DamienMcKenna’s picture

Berdir’s picture

This has been part of redirect 8.x-1.x for a long time, see also #2704213: "Redirect from non-canonical URLs to the canonical URLs" not working with language code in url for refactoring that again to get something that is close to what is being worked on for core itself.

DamienMcKenna’s picture

@Berdir: That's awesome, thanks for the update!

ciss’s picture

Status: Reviewed & tested by the community » Needs work

Something I just noticed:

+++ b/redirect.module
@@ -309,25 +342,59 @@ function redirect_init() {
+  $langcode = isset($options['language']->language) ? $options['language']->language : '';

$options doesn't seem to be defined anywhere.

We've also noticed that the deslash option is quite aggressive, redirecting POST requests to a custom services endpoint to their deslashed GET version. I'm pretty certain that any request other than GET should be left alone.

kscheirer’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Category: Bug report » Task
Status: Needs work » Reviewed & tested by the community
Issue tags: -7.x-2.0 release blocker +7.x-1.0 release blocker

while comment #239 is correct this patch works well for many people (myself included) on production environments. Given this is listed as a blocker for a 1.0 release (in #236) , I think we could handle the $options['language'] in a new issue and commit this.

Alternatively, let's move this back to a 2.0 release blocker and move forward with 1.0. There does not seem to be any difference between the 1.x and 2.x branches at this time.

eelkeblok’s picture

Status: Reviewed & tested by the community » Needs work

Unfortunately, we've found a security issue that is introduced by this patch. My colleague will upload an update shortly.

r.van.doorn’s picture

Status: Needs work » Needs review
FileSize
14.01 KB
699 bytes

For my current project we found a vulnerability in the patch from #239.
When 'Redirect from non-clean URLs to clean URLs.' is enabled you can use the q variable for an open redirect.
I've made a small change to the patch that blocks external urls when redirecting with $_GET.
It's pretty much the same code that was added tot drupal_goto in 2010 (https://www.drupal.org/node/731710)

eelkeblok’s picture

+++ b/redirect.module
@@ -309,25 +342,65 @@ function redirect_init() {
+      // We do not allow absolute URLs to be passed via $_GET, as this can be an attack vector.

Nitpick: this comment line exceeds 80 characters which is a violation of the coding guidelines.

Otherwise, the resolution of the open redirect issue looks fine.

eelkeblok’s picture

Status: Needs review » Needs work
eelkeblok’s picture

I did a full once-over of the patch. I have the actual code changes ready to go, I just need to turn them into a patch. Most stuff is coding guidelines, although I also addressed the points in #239.

  1. +++ b/redirect.admin.inc
    @@ -670,40 +670,78 @@ function redirect_settings_form($form, &$form_state) {
    +      '#description' => t('Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog. <front> is the front page.'),
    

    This call to t() does not work, because the string is single quoted, but also contains single quotes. Not sure why it isn't failing harder than it is all I am seeing is that the option description does not show up (the option itself shows up when the one above it is enabled).

  2. +++ b/redirect.module
    @@ -226,23 +228,54 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) {
    +    return redirect_redirect((object)array('redirect' => '', 'type' => 'global'));
    

    Coding standards dictate there needs to be a space between the cast and the variable.

  3. +++ b/redirect.module
    @@ -226,23 +228,54 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) {
    +    return redirect_redirect((object)array('redirect' => $alias, 'type' => 'global'));
    

    Same thing.

  4. +++ b/redirect.module
    @@ -226,23 +228,54 @@ function redirect_url_inbound_alter(&$path, $original_path, $path_language) {
    +      return redirect_redirect((object)array('redirect' => $uri['path'], 'redirect_options' => $uri['options'], 'type' => 'global'));
    

    And again. Also, this line gets too long according to phpcs.

  5. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +    redirect_redirect((object)array('redirect' => $request_uri, 'type' => 'global'));
    

    Again space after the cast.

  6. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +  // Strip index.php
    

    Inline comment needs to end in a full stop (or other ending punctuation).

  7. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +      redirect_redirect((object)array('redirect' => $request_uri, 'type' => 'global'));
    

    And again the cast thing.

  8. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +      redirect_redirect((object)array('redirect' => '', 'type' => 'global'));
    

    ...

  9. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +    redirect_redirect((object)array('redirect' => rtrim($request_uri, '/'), 'type' => 'global'));
    

    Cast. And also this line doesn't pass the length test according to phpcs.

  10. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +    redirect_redirect((object)array('redirect' => $request_uri . '/', 'type' => 'global'));
    

    Cast.

  11. +++ b/redirect.module
    @@ -309,25 +342,65 @@ function redirect_init() {
    +      redirect_redirect((object)array('redirect' => $request_uri, 'type' => 'global'));
    

    And the cast thing one final time.

  12. +++ b/redirect.module
    @@ -740,7 +813,7 @@ function redirect_validate($redirect, $form, &$form_state) {
    +function redirect_object_prepare(stdClass $redirect, $defaults = array()) {
    

    This seems a small API change that doesn't really belong in this patch, although I expect this will be a slight improvement, since the function would error out anyway when something other than an object was passed.

  13. +++ b/redirect.module
    @@ -1122,7 +1195,21 @@ function redirect_redirect($redirect = NULL) {
    +  // Prevent a path like 'index.php?q=node/1' from redirecting to '?q=path-alias'
    

    Line just slightly too long, causing ugly yellow lines in my code editor.

eelkeblok’s picture

Here's the patch implementing the above and #239.

eelkeblok’s picture

Status: Needs work » Needs review
Phil Wolstenholme’s picture

Am I imagining things or was this in the 8.x branch and then removed?

Our redirect.settings.yml file contains things like frontpage_redirect: true and deslash: true but these no longer have an effect in 8.x-1.0-alpha4.

eelkeblok’s picture

I think you're right; when looking in the copy of the code I have at least there is some stuff that seems to implement the frontpage_redirect option. However, since this issue is about getting this *into* the D7-version (and considering it already is an extremely long issue as it is), please create a new issue about this. (Or maybe do a little more thorough search that I did for issues about temporarily disabling this, or something).

kscheirer’s picture

Status: Needs review » Reviewed & tested by the community

patch in #246 is working for me, thanks!

giupenni’s picture

#246 works for me

klonos’s picture

Just a quick question: after this has been implemented, is there any reason for site that uses both redirect and global_redirect to actually keep both modules enabled? If not, it would be useful to:

a) make sure that all respective settings from globai_redirect are being "migrated" over to redirect
b) there is a warning in the site status stating the fact that global redirect can now be safely disabled and then removed.

Just my 2c

eelkeblok’s picture

Status: Reviewed & tested by the community » Needs work

Good point. Should we maybe go as far as turning the module off in an update hook (and still check in the status message whether it was turned on again)?

eelkeblok’s picture

Here's some preliminary steps (an update hook and an addition to the install hook to migrate the settings). However, when I was creating the mapping for the settings, I found that at this point at least, Global Redirect seems to do a bunch more stuff than this patch is adding to Redirect. These settings from Global Redirect have no equivalent in this patch:

  • trailing_zero
  • menu_check
  • case_sensitive_urls
  • language_redirect
  • canonical
  • content_location_header
  • term_path_handler
  • comment_to_node

See http://cgit.drupalcode.org/globalredirect/tree/globalredirect.admin.inc?... for a description of what they do (canonical and content_location_header might legitimately be referred to metatag module, I think).

Simply disabling the module and displaying a warning if it is enabled again seems a much less appealing option now. How should this be handled? Should Global Redirect remain a valid addition for some more specialized options..? Should the extra options also be merged into this patch? Maybe later in a follow-up? Not entirely sure what the best path forward is.

eelkeblok’s picture

Status: Needs work » Needs review
vinayjain’s picture

It would be great to see the case-sensitive URL option (mentioned in #224), which was part of Global Redirect (as noted in #254), included in this module. The feature allows one to prevent duplicate URLs (case variants), which was among the primary goals of Global Redirect. There seems to be no good solution to achieve that functionality (I'd love to know if there is any).

kclarkson’s picture

@eelkeblok,

My vote would be to add the case-sensitive URL option in there. Apply the patch and then create tickets of all the other features. It will be much easier to maintain and check the progress with different tickets.

tomsegarra’s picture

As recommended in the previous two comments, I've implemented the case-sensitive URL option, along with a test for that option.

This seems to be in good shape. I agree with #257: it'd make sense to defer the rest of the Global Redirect features for now, so we can get a stable release and prevent this convoluted issue thread from getting longer.

das-peter’s picture

Status: Needs review » Needs work
+++ b/redirect.module
@@ -309,25 +354,72 @@ function redirect_init() {
+    list($language, $raw_path) = language_url_split_prefix($request_uri, language_list());

Just ran into trouble with this. $request_uri easily can be the processed value from $_GET['q'] which means it never has a language prefix.
I suppose we always should use the raw version returned by request_path() to see if the language prefix was / is set.

rajiv.singh’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc3
FileSize
14.25 KB

Re rolled patch #166

DamienMcKenna’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 260: redirect-global-905914-260.patch, failed testing. View results

ciss’s picture

@rajiv.singh Please don't reroll ancient patches.

c7bamford’s picture

Changed the update number from 7103 to 7104 to work with the newest dev version of this module.

c7bamford’s picture

The previous patch is an update of patch 258.

Chris Matthews’s picture

After trying to apply the patch in #264

redirect.install
error: patch failed: redirect.install:432
error: redirect.install: patch does not apply

redirect.module
error: patch failed: redirect.module:1122
error: redirect.module: patch does not apply

redirect.test
Hunk #1 succeeded at 311 (offset 27 lines)

eelkeblok’s picture

Issue tags: +Needs reroll
eelkeblok’s picture

Issue tags: -Needs reroll

Actually, I may have been a bit quick. To what version did you apply the patch? #264 says it is meant for the latest dev version.

Alan D.’s picture

Status: Needs work » Needs review

Changing status back . The invalid patch in #260 changed this to Needs work, I personally haven't reviewed this at all.

This should also check if the latest patch (#264) applies to dev ;)

Status: Needs review » Needs work
Chris Matthews’s picture

To what version did you apply the patch?

>> 7.x-1.x-dev

Alan D.’s picture

Issue tags: +Needs reroll
c7bamford’s picture

Rerolled again. If you've used previous versions of this patch, you're going to have to change update numbers to get all the updates to work. This is for the d7 1.x branch on commit e61ef3d.

c7bamford’s picture

Issue tags: -Needs reroll

Removed needs reroll tag

c7bamford’s picture

Same patch, but with fewer errors.

kscheirer’s picture

Status: Needs work » Needs review
Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch in #275 does not apply to the latest 7.x-1.x-dev and needs another reroll.

redirect-d7-1.x-merge_global_redirect-905914-275.patch:133: trailing whitespace.
  
redirect-d7-1.x-merge_global_redirect-905914-275.patch:334: trailing whitespace.
  
redirect-d7-1.x-merge_global_redirect-905914-275.patch:441: trailing whitespace.
  
Checking patch redirect.admin.inc...
Checking patch redirect.install...
error: while searching for:
  if (db_table_exists('path_redirect')) {
    drupal_set_installed_schema_version('redirect', 6999);
  }
}

/**

error: patch failed: redirect.install:126
error: redirect.install: patch does not apply
Checking patch redirect.module...
Checking patch redirect.test...
Hunk #1 succeeded at 341 (offset 30 lines).
c7bamford’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
18.51 KB

This patch applies to 7.x-1.x at commit 523778d3.

Chris Matthews’s picture

This issue is a child of #2514248: Plan for Redirect v7.x-1.0 release. Should it continue to be blocker for a full 7.x-1.0 release of redirect?

jedsaet’s picture

Re-roll of the patch in 278 against commit 7f9531d0 for 7.x-1.x

andralex’s picture

The patch from #280 successfully applied locally.
I've found a few coding standard issues:

  1. +++ b/redirect.admin.inc
    @@ -758,6 +811,17 @@ function redirect_settings_form_submit($form, &$form_state) {
    +    form_set_error('info', t('You can not have both %deslash and %add_slash enabled.', array('%deslash' => rtrim($form['globals']['redirect_global_deslash']['#title'], '.'), '%add_slash' => rtrim($form['globals']['redirect_global_add_slash']['#title'], '.'))));
    

    If the line declaring an array spans longer than 80 characters, each element should be broken into its own line

  2. +++ b/redirect.module
    @@ -315,25 +360,74 @@ function redirect_init() {
    +      redirect_redirect((object) array('redirect' => $request_uri, 'type' => 'global'));
    

    Line indented incorrectly; expected 4 spaces, found 6

  3. +++ b/redirect.module
    @@ -315,25 +360,74 @@ function redirect_init() {
    +          redirect_redirect(
    

    Line indented incorrectly; expected 8 spaces, found 10

  4. +++ b/redirect.module
    @@ -315,25 +360,74 @@ function redirect_init() {
    +          redirect_redirect((object) array('redirect' => $request_uri . '/', 'type' => 'global'));
    

    Line indented incorrectly; expected 8 spaces, found 10

  5. +++ b/redirect.test
    @@ -341,4 +341,22 @@ class RedirectFunctionalTest extends RedirectTestHelper {
    +  function testCaseSensitiveUrls() {
    

    Missing function doc comment.
    Visibility must be declared on method "testCaseSensitiveUrls"

  6. +++ b/redirect.test
    @@ -341,4 +341,22 @@ class RedirectFunctionalTest extends RedirectTestHelper {
    +  }
    

    Expected 1 blank line after function; 0 found

andralex’s picture

+++ b/redirect.install
@@ -475,3 +477,63 @@ function redirect_update_7104() {
+  $variables = array(
+    'redirect_global_home' => 'frontpage_redirect',
+    'redirect_global_clean' => 'nonclean_to_clean',
+    'redirect_global_canonical_front' => 'frontpage_redirect',
+    'redirect_global_deslash' => 'deslash',
+    'redirect_global_admin_paths' => 'ignore_admin_path',
+    'redirect_global_case_sensitive' => 'case_sensitive_urls',
+  );

This also needs to be added into redirect_variables() so variables will be removed in
hook_uninstall()

NWOM’s picture

Status: Needs review » Needs work

Needs work including the changes from #281 and #282.

andralex’s picture

Status: Needs work » Needs review
FileSize
18.93 KB
2.57 KB

Here is reroll of patch #280 with changes from #281 and #282.

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #284 is working for me. Marking as RTBC.

Kristen Pol’s picture

Assigned: Unassigned » Kristen Pol

Assigning to myself as I'm triaging all RTBC issues.

Berdir’s picture

Note that this is a D7 issue, I'm not maintaining that, only 8.x-1.x, that was the original agreement with Dave and i think we shouldn'r be making non-trivial changes to 7.x-1.x at this point.

Kristen Pol’s picture

Status: Reviewed & tested by the community » Postponed

Thanks @Berdir. Yeah, I'm assigning everything that's RTBC to me in order to triage and see what is still valid and what's not and hopefully move issues forward or close them out.

I agree that this is a major issue and might be dicey to merge at this point. It's a shame though given everyone's hard work. Though, there is a patch people can use that was RTBC'ed so they can always use that.

I'd love to give issue credit for everyone's hard work on this but let me think how to best do that while marking this one as "won't fix". Postponing for the moment.

steinmb’s picture

Given the current activity on D7 modules it might be difficult to legitimise the use of developer/maintenance time doing so. The issue is marked with "needs tests" though the patch introduce a single test with two assertions. Not sure if the tag was not removed or that this is too little tests. That might tip the scale. We could create a new branch and move this to, 7.x-2.x as an experimental feature. Not sure we win anything by doing so?