6

Im using Pathauto to make my URLs nice and I may want to change the paths in the future. On some pages Im manually lining to other nodes.

The issue is that if I code the nice URL then the link will be broken if I change the Pathauto settings in the future. If I link to node/(the node id) then the link will always work, but its bad for SEO to not have keywords in the anchor text.

Is there a way to code in the NID so it always works but on the page show the nice URL?

3 Answers 3

8

I would, as Splat mentioned, check out the Global Redirect module, which will help out with google not seeing node/FOO and pretty/path pointing to identical content. If, however you are wanting to make sure that when engines scan your page content and pretty/path shows up inside the HTML, you can either continue to hardcode the paths, or create a function that returns the aliased path based on the nid.

function make_my_path($nid) {
  $pretty_path=drupal_get_path_alias('node/' . $nid);
  return $pretty_path;
}

Then use that (or drupal_get_path_alias() directly) in your templates or preprocess functions, or just use l(). If it is passed 'node/FOO' as the path, it will return the aliased path if one is set. (Unless you explicitly tell it not to; see url().)

So, for example, print l('Hello World','node/23'); should return <a href="/pretty/path/to/node/23">Hello World</a>.

1
  • Thanks. Shame their isn't a module to remove the need for so much code.
    – Evanss
    Feb 29, 2012 at 17:45
3

If you're using CKEditor, you should use the CKEditor Link module. It allows searching content by title to insert, and in Drupal it saves the link as /node/[ID]. Then a text filter (which you'll need to enable for each text format it's being used on) replaces that URL with the current path alias in the rendered page.

2

I think you're looking for the Global Redirect module. This will make sure whenever you link to node/x that anyone following the link is redirected to the clean URL for that node.

1
  • No, I want it so on the page with the link the actual html isn't node/x but instead it's the nice Pathauto URL. Users will never notice the difference, but search engines do. Thanks
    – Evanss
    Feb 29, 2012 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.