Experimental project

This is a sandbox project, which contains experimental code for developer use only.

May 23rd, 2011 Update: Use pathologic module instead with one configuration step (add / to the Also considered local: paths) and you will have this same functionality.

The purpose of this filter is to seamlessly update the node/123 pattern found in posts to the equivalent node alias without altering any actual content. This filter also replaces user/123 and taxonomy/term/123 paths with their equivalent aliases.

It is important to use the normal path when inter-site linking so that if aliases change, you don't loose your links. However, it is preferable for the user experience to "see" the aliased path when hovering, clicking or copying a link.

How it Works:
Here's what the author enters...

This is a link to <a href="/node/2">node 2</a>. The href will be replaced with the node alias.
This is a link to <a href="/taxonomy/term/1">taxonomy term 1</a>. The href will be replaced with the taxonomy alias.
This is a link to <a href="/user/1?destination=node/2">user 1</a>. Notice the replacement in the href tag, also in the destination query string, node/2 is replaced with the node alias.
Finally, this is a text reference to node/2, it will not be replaced by the filter because it's not part of a tag attribute or url query string.

Here's what is rendered in the browser as code...

This is a link to <a href="/content/filter-test">node 2</a>. The href will be replaced with the node alias.<br>
This is a link to <a href="/category/zoo-animals/monkeys">taxonomy term 1</a>. The href will be replaced with the taxonomy alias.<br>
This is a link to <a href="/users/aklump?destination=content/filter-test">user 1</a>. Notice the replacement in the href tag, also in the destination query string, node/2 is replaced with the node alias.<br>
Finally, this is a text reference to node/2, it will not be replaced by the filter because it's not part of a tag attribute or url query string.

Key points to note when using this filter:

  1. The filter DOES NOT ALTER the original user post, so changing aliases of the target node will NOT break your link.
  2. The filter is currently set to only replace when normal paths are found inside an <a> tag or as part of a query string. This is controlled by a single regex expression. The regex expression that is used can be altered by setting the variable 'node_alias_filter_regex' via another module. (So this filter can be extended easily in code.)

Similar Projects:

  1. Global Redirect
  2. Link Node

This differs from Global Redirect in that:

  • The alias is inserted in the page code when the page is rendered, rather than a server redirect after the user clicks the link. This has the benefit that the user will see the alias when they hover or copy the link or view page source.

This differs from Link Node offering advantages such as:

  • If a site is already built out and nodes created which contain the pattern node/123--say if it was built without path auto--this filter will seamlessly upgrade that site. In addition, it would downgrade just as easily if the filter was disabled. In other words, no special syntax is needed in existing posts to get it to subtitute out the aliases immediately.
  • Using the native <a>tag, allows for easier control if you want to add classes and other attributes to the link tag itself, without having to utilize a secondary syntax. The level of abstraction is one less, so to say.</a>
  • Integration with WYSIWYG solutions: since this module doesn't require "non-html" syntax. The WYSIWYG integration is able to provide title, class, and other tags through it's UI.

Project Information