This looks like a nice module, but I can't seem to get it to work at all. I am using the latest cvs checkouts of the 4.7 branch of drupal and globalredirect.

E.g. I have aliased 'about' to 'node/21', so I was expecting that when I access 'node/21' I would be redirected to 'about', but it just displays 'node/21'. No change from before I installed the module.

Any ideas?

CommentFileSizeAuthor
#29 global_module_redirect.patch577 bytesboreg

Comments

RayZ’s picture

Very strange ... I've gone so far as to disable all other modules besides path, page, menu and globalredirect. I've cleared the cache, I've changed the default front page. My aliases work just fine, but nothing will get it to redirect.

I assume this actually does work for somebody, right?

nicholasthompson’s picture

It certainly works for me...

Check this:
http://www.sportbusiness.com/node/160637
goes to:
http://www.sportbusiness.com/news/160637/two-united-directors-quit

just to confirm - you have mapped node/21 to about and when you go to node/21 (not node/21/ - no trailing slash) it doesn't redirect to the alias?

I cant imagine why this would happen. I'm using the 4.7.3 for our site - I'm not sure what you mean by CVS... CVS is currently Drupal 5.0 isn't it?

RayZ’s picture

just to confirm - you have mapped node/21 to about and when you go to node/21 (not node/21/ - no trailing slash) it doesn't redirect to the alias?

Correct. No trailing slash. No redirect.

I am running on a current CVS checkout of the DRUPAL-4-7 branch. This is basically 4.7.3, plus any bug fixes that have gone into that branch since the release. This makes it much easier to upgrade ... when 4.7.4 comes out all I have to do is type 'cvs up -dP' in my drupal directory and it's upgraded. No downloading, unzipping, copying files, etc.

I suppose it's *possible* that a change since 4.7.3 breaks your module, but that shouldn't happen on a stable branch.

So I am baffled. For what it's worth the path_redirect module *is* working, as are all other installed modules. I have clean URLs enabled, and I have my modules installed in sites/default/modules. I get the same behavior on my dev site running on Mac OS X and my production server running on Linux.

Any suggestions for helping to debug this?

nicholasthompson’s picture

Well well... This is a genuine head scratcher!

Ok... What happens if you disable path redirect? I haven't tried that module yet. Maybe its causing an issue?

Umm.. Try chucking an echo of something and then an exit() in the main function just to check its actually running.

Do you have Error reporting enabled and, if so, what level? Have you tried E_ALL to see if the module is throwing any errors?

RayZ’s picture

OK, I have error_reporting = E_ALL & ~E_NOTICE. Turning off all other modules except menu, path, page, and globalredirect makes no difference. If I slip the following code into globalredirect_init() right after the call to drupal_lookup_path() ...

echo "\n";
echo "\$path = '$path'\n";
echo "\$alias = '$alias'\n";
echo "drupal_get_path_alias(\$path) = '" . drupal_get_path_alias($path) . "'\n";
echo "drupal_lookup_path('alias', 'node/21') = '" . drupal_lookup_path('alias', 'node/21') . "'\n";
echo "drupal_lookup_path('alias', 'node/23') = '" . drupal_lookup_path('alias', 'node/23') . "'\n";
echo "drupal_get_path_alias('node/21') = '" . drupal_get_path_alias('node/21') . "'\n";
echo "drupal_get_path_alias('node/23') = '" . drupal_get_path_alias('node/23') . "'\n";
echo "\n";
exit();

... and then access 'node/23' (which is aliased to 'about/cornell'), I get the following ...

$path = 'node/23'
$alias = ''
drupal_get_path_alias($path) = 'node/23'
drupal_lookup_path('alias', 'node/21') = 'about'
drupal_lookup_path('alias', 'node/23') = ''
drupal_get_path_alias('node/21') = 'about'
drupal_get_path_alias('node/23') = 'node/23'

If I access 'node/21' (which is aliased to 'about'), I get the following ...

$path = 'node/21'
$alias = ''
drupal_get_path_alias($path) = 'node/21'
drupal_lookup_path('alias', 'node/21') = ''
drupal_lookup_path('alias', 'node/23') = 'about/cornell'
drupal_get_path_alias('node/21') = 'node/21'
drupal_get_path_alias('node/23') = 'about/cornell'

So it looks like the alias lookup is failing for the current page? Hmmm.

RayZ’s picture

OK, looks like it is a bug in drupal core introduced since drupal 4.7.3 was released. It was introduced by this patch http://drupal.org/node/83234. Backing out this patch fixes the problem.

RayZ’s picture

I submitted an issue for core here http://drupal.org/node/89947.

nicholasthompson’s picture

Nicely tracked down - So basically GlobalRedirect IS broken in 4.7.4?

RayZ’s picture

It appears so to me ... but I'd love to have someone else confirm it.

ednique’s picture

I noticed too that the global redirect does not work on 4.7.4 anymore...

RayZ’s picture

Fixed by this patch http://drupal.org/node/65493

Robardi56’s picture

So, is this global redirect module working or not ? It seems it works fine on the site of the author ?

Brakkar

RayZ’s picture

I believe the conclusion is that it works fine on drupal 4.7.3 (and probably earlier 4.7.x), but not on 4.7.4. Unfortunately, 4.7.4 introduced a bug that breaks the functionality of the globalredirect module. Applying the patch in #14 of http://drupal.org/node/65493 fixes the bug in 4.7.4 that broke this module.

nicholasthompson’s picture

Status: Active » Needs review

Thanks for all that RayZ - I've been so busy recently I haven't had a chance to test if this does indeed fix Global Redirect for 4.7.4 - but if it does, great work. Much appreciated...

Fyi, here is a link directly to post #14.

nicholasthompson’s picture

Status: Needs review » Fixed

I can confirm that applying that patch does indeed solve the redirect issue (not being redirected to the alias when you visit the node directly). I have applied the patch to my live site and all seems to be working ok... I'll mark this as closed unless anyone can find any problems with the patch.

hass’s picture

please check out http://cvs.drupal.org/viewcvs/*checkout*/drupal/drupal/includes/path.inc... this looks like the next version... and not patch #14! Asside i found another bug in the module caused by drupal_goto($alias);...

Anonymous’s picture

please check out http://cvs.drupal.org/viewcvs/*checkout*/drupal/drupal/includes/path.inc... this looks like the next version... and not patch #14! Asside i found another bug in the module caused by drupal_goto($alias);...

How is this checkout supposed to tag to DRUPAL-4.7? Nevermind I'll go ask on the development list but I think if I'm looking at the DRUPAL-4.7 branch viewcvs should tag the checkout. Just thought I'd mention it here for caution sake.

Anonymous’s picture

*MY BAD* - never mind the previous post.

hass’s picture

ok, not "checking out" the file from CVS... only download it .-)

Christoph C. Cemper’s picture

hmm - I got it working with

path.inc - rev 1.4.2.4
globalredirect.module - rev HEAD

mattman’s picture

Does anyone know what is going on with this module and 4.7.4? I'm using path.inc 1.4.2.5 and globalredirect 1.5 (HEAD - I think). The module is executing - because a path with a trailing "/" is stripped. However, the redirect to the actual alias is not working. I'm watching my access log using tail -f and there's no 301 to the proper alias.

mattman’s picture

Nevermind!!! stupid me. One of those bonehead developer moves. You know, you alter the data while testing your code modifications and you forget to change it back - and you keep testing against the same bad data. This will make more sense. I was testing against a url alias I had modified to use a preceding slash "/node/200", where I should have changed it back to "node/200".

Of course, drupal won't find the alias to "node/200" when it doesn't exist.... Arggggg. Haven't we all done that? The real sucky part is the fact that you tear your hair out going around and around when it's your data that has the issue - not your code. And you're the one that caused the problem. :(

Anonymous’s picture

Just wanted to point out that, after upgrading to 4.7.5, the redirect seems to be working again (I'm using the "unpatched" version).

ednique’s picture

Yep, same for me... working again...

RayZ’s picture

For me, it appears to work for all but the front page. I assume it is still due to http://drupal.org/node/65493, which has not yet been fixed.

In my case, the variable site_frontpage = 'frontpage' and 'node/312' is aliased to 'frontpage'. It will redirect 'http://example.com/node/312' to 'http://example.com/frontpage'. But it won't redirect 'http://example.com/frontpage' to 'http://example.com/'.

nicholasthompson’s picture

I confirm - 4.7.5 is much better for alias lookups!

Question - why would you alias a node to frontpage? Why not just set that node as the frontpage setting in admin>settings?

RayZ’s picture

Ah ... hmmm ... I see your point. I guess I set up my site_frontpage in admin>settings before deciding how I was going to create the home page (a node, a view ...?).

However, that still doesn't change the fact that globalredirect does not work for the home page. When I change my site_frontpage to 'node/312' and get rid of the 'frontpage' alias, then access node/312, there is no redirect.

I think if http://drupal.org/node/65493 gets fixed that should take care of both scenarios, but I haven't been able to check the latest patch there.

Anonymous’s picture

Status: Fixed » Closed (fixed)
boreg’s picture

StatusFileSize
new577 bytes

Hi,
I'm not good at English, so maybe i overlook something, so feel free to correct me:

Isn't better to patch the globalredirect.module file than the core files?

I have Drupal 4.7.4 and this my "fast and inept" solution (also in the patch file) works for me:

function globalredirect_init() {
  if(isset($_REQUEST['q'])) {
    $path = $_REQUEST['q'];
    $alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
    
    if (!empty($alias)) {
      header("HTTP/1.1 301 Moved Permanently");
      drupal_goto($alias);
    }
  }
}