Path Redirect question

Events happening in the community are now at Drupal community events on www.drupal.org.
kirkcaraway's picture

The problem I am trying to solve is that I have advertising-related nodes that expire and unpublish after a certain number of days, and I want to redirect traffic from these unpublished nodes to one specific page instead of users getting the "page not found" or access denied errors.

I have found a way using Rules to make this work, but after reading the following discussion, I'm worried this will bog down my system when the site goes live: http://groups.drupal.org/node/93624

I have set up a rule set with an argument for content, conditions for node type and to check if node is published, and the action to redirect path to a specific page. Then I have a triggered rule that triggers on "Content is going to be viewed" with a condition for node type, and the action to trigger my rule set.

However, after reading the above discussion, I'm worried that this rule will be checked with every single view of any node on the site. I would like to see it checked only if a particular node type is viewed. Am I getting around this problem by having a separate triggered rule and rule set?

If not, is there a better way to achieve this same goal without the performance hit?

Thanks.

Comments

I probably wouldn't create a

caschbre's picture

I probably wouldn't create a rule that triggers on each view of the node to determine if the user should be redirected. What you could probably do is create a rule that fires on node creation and checks if it is an ad node. If it is then the rule can create a scheduled rule to a) unpublish the node on X date, and b) create the redirect.

I don't think that is how the

kirkcaraway's picture

I don't think that is how the redirect action works, at least from what I can tell from my experiments. I tried setting up a redirect triggered when the node moves to unpublished state, and got nothing. I believe redirects aren't something that is permanent like URL aliases, and therefore have to be triggered each time the node is viewed. I could be wrong about this, hopefully.

I tried using URL aliases, and that didn't work, either, because setting an alias to an existing path breaks it. Even if this method worked, creating aliases presents another challenge, as I expect some of these ad nodes will get renewed and re-published. That would require yet another process to remove the aliases.

Thanks for the input.

Ah, you're right. I'm

caschbre's picture

Ah, you're right. I'm thinking of something different.

One option then might be to create a custom rule action that would create the redirect in the context of the URL redirect module.

Itangalo also has a good suggestion. Use the CCK Redirection module. The rule action would populate that field with the destination URL on a schedule... or when the node is set to unpublish.

Also: the 404 page settings

itangalo's picture

Drupal has settings for which page should be loaded on page-not-found errors. You find it under site configuration somewhere.

If you use it, all your 404s will go to a particular page – not only those related to old advertisment pages.

There is also the CCK Redirection module that could help in this situation.
Haven't tried it in heavy-load environment, so I can't say how it performs compared to Rules.

Good luck!
//Johan Falk, NodeOne, Sweden

Having all 404s go to the

kirkcaraway's picture

Having all 404s go to the same page wouldn't work in this case. I will give the CCK Redirection module a try. I haven't played with this before, but I would assume that I would have to set up a rule to fill this CCK field once a node has been unpublished, right?

Thanks.

Should work

itangalo's picture

Having a Rule fill in the redirection field should work just fine. If there are just a few nodes there is also the option of doing it manually. :-)

Cheers!

Unfortunately, I have been

kirkcaraway's picture

Unfortunately, I have been unable to make the redirect field work, due to the fact that the nodes are unpublished.

But it has made me re-examine the purpose of this exercise. I don't want users or search engines to see broken links, but I do want to hide the content of expired ads.

Perhaps a better way would be to keep the nodes in their published state after they expire, but find a way to create an overlay or some other method to obscure the content on the page (but still available for search engine indexing), and tell users that the ad is expired and give them a link to the current ads.

Does anyone know how to best do this? Thanks.

Here's a possibility that may

caschbre's picture

Here's a possibility that may work for you...

1) Keep your ads as nodes.

2) Create a view that accepts the ad nid and displays that single ad.
- The view can filter by expiration date so if the ad expires it will not show it.
- The view can also display content when no results are returned. This gets around the 404s, etc.

3) Now... to keep users from viewing the ads as node pages, use the CCK redirection. Populate this field with the view URL (including nid argument). This keeps users from viewing the ad node and redirects them to the view.

This way you don't have to worry about creating redirects, 404s, broken links, etc. Rules may be the easiest way to auto-populate the CCK redirection field.

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: