So it took me a while to figure out what was going on here. Let me help set up my scenario:
I have Node Hierarchy installed which uses views to display the children.
I have my announcements which use the path and PathAuto:
/announcement -> node/1 (announcement list via Views)
/announcement/2011-01-20/old-title -> node/2
This announcement recently had it's title changed and because PathAuto is setup to chance the URL based on the title, the URL is now:
/announcement/2011-01-20/new-title -> node/2
However when you go to /announcement/2011-01-20/old-title... you wouldn't get a redirect. Instead it would display /announcement and because it's a view was treating the rest of the URL as arguments.
I did a little debugging and found out that the $_GET['q'] that path_redirect_get_path() was returning:
/node/1/2011-01-20/old-title
At first I thought maybe some sort of weight or rewrite needed to happen, but then found out that the $_GET['q'] was being modified in Drupal core (includes/path.inc) before any modules had a chance to intercept:
function drupal_init_path() {
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
}
So to get Path Redirect to work for me, I had to modify using this patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | path_redirect-url-query-ml.patch | 2.73 KB | bderubinat |
| #1 | path_redirect-url-query.patch | 2.97 KB | markhalliwell |
| path_redirect-url-query.patch | 570 bytes | markhalliwell |
Comments
Comment #1
markhalliwellOk, so I took the liberty of looking at this a little more in detail. I noticed that if you want to show the user a message, you are left with going to the original URL and then redirected via a meta tag after 10 seconds. There is two problems with this:
1) When you are left navigating to the original content, this could be the parent page or even a 404, which leads into point:
2) Using this method, it doesn't present the browser/agent with the appropriate code of 301 (or which ever you set in path_redirect settings.
This new patch takes out the elseif that is in there and combines it with the else so you are automatically redirected to the correct page with the correct header code. If you wish to warn you user, then display the message. Also changed the verbiage accordingly and included the source URL that the user requested.
Comment #2
markhalliwellAlso, if you're interested. I wouldn't mind being a co-maintainer.
Comment #3
dave reidI'm curious, why can't you create a redirect from 'node/1/2011-01-20/old-title' => 'node/2'. Will that not work?
The message functionality is intentional that you view the 404 page first. Otherwise it doesn't make sense since the redirect is handled automatically for you.
Comment #4
markhalliwellAs far as changing
$_GET['q']to$_REQUEST['q']:When PathAuto updates the node's the URL, it creates a redirect in Path Redirect as 'announcement/2011-01-20/old-title' not 'node/1/2011-01-20/old-title'. So when Path Redirect calls
path_redirect_get_path(), which is really just a wrapper for getting$_GET['q'], it returns Drupal's "internal path" of 'node/1/2011-01-20/old-title'. This is because in Drupal's core, the path is already converted and$_GET['q']is set to Drupal's internal path before it is even touched by modules. Thus, it will return the closest matching alias and then tack on the remaining "path" as arguments. And while, yes, I can manually set this redirect, it would be pointless when it supposed to do it automatically in the first place. I'm actually very surprised that this wasn't caught and might explain why you seem to have/had quite a few "this doesn't work or I can't get this work" issues.Path works in the following way. Say you have the following two nodes:
/announcement
/announcement/page
And you delete the last one, it will match to the next "higher" alias and return the rest of the path as arguments, /announcement and return a 200 (found) code. Not a 404 (page not found).
So when I have /announcement/2011-01-20/old-title, and the title changes, this alias is no longer applicable and I end up viewing the node associated with /announcement.
As far as the the messaging goes, that would work if the page that is returned is a 404 and not an actual node as mentioned above. Thus, it would be nice to simply redirect to the correct page (with the correct redirect HTTP header) in the first place and just display the message, if checked, on that page.
Comment #5
bderubinat commentedThanks Mark,
Also note that when you have a multilingual site with url such as www.foobar.com/fr/your/page/path , getting _REQUEST instead of _GET will give you "fr/your/page/path" and not "your/page/path".
Here is a patch.