Redirect comment permalinks to node paths (Drupal 7)

Thu, 2012-05-31 08:57

One of the bad thing in Drupal 7 is that each comment has its own permalink and when a user is viewing the comment, the actual node content is shown.
There are no robots.txt rules to prevent this from happening so we are in a risk of getting duplicate content problems, and getting thousands of 404 (Page not found) errors for deleted comments (and 403 errors for unpublished comments). It's true that this situation is same for nodes. But if your site has comments enabled fro anonymous users, anyone can (or at least try to) make a broken link in your site (404 or 403)

I have come with a solution for this.

What about redirecting the user who opens a http://example.com/comment/x link to that comment's parent node ?

For an example, if there is a comment with ID 123 in node with ID 321, if a user opened http://example.com/comment/123 , they will see the contents of node 321 and the comment itself.
Isn't that same as http://example.com/node/321 ? Even worse, if a node receives 100 comments. That means there will be 100 links that displays the same content. SEO goes to hell.

So I made a (Sandbox) module that does the trick. If you want to try it, go to the home page and click on a link from the block in left sidebar.
you will see that the comment URL points to http://ayesh.me/comment/5633#comment-5633 but after you click on that URL, you are ended up in http://ayesh.me/content/idm-cc-firefox-add-firefox-11-and-12?page=2#comment-5633 where is the original node path.

To get that functionality, use Permalinks to Nodepath module!

I wrote this (very) tiny module hoping you will find it useful. I don't think this module is good/useful enough to promote as a full module (rather than a sandbox one). Let me know of it helps!