I work on a very large drupal site with over 100,000 nodes and at least 40 different node types. We use nodes for many many different things. Just recently realized we were doing nothing about preventing our (anon) users from going to full node view pages for even the node types which we don't want to display as full pages.

This combined with the idea that "No one would ever, on any site, want to show a url like node/12345" had me add this little snippet to a _menu hook in a module of ours:

  global $user;
  if (!$user->uid) {
    if (arg(0) == 'node' && !arg(2)) {
      if (drupal_get_path_alias("node/" . arg(1)) == "node/" . arg(1)) {
        drupal_goto("search");
      }
    }
  }

Doesn't this seem like a reasonable thing for pathauto to do, at least as an option? That is to say, for any node view (at least for anon), if a node type is NOT aliased, then go to a configurable redirect page.

Just a thought; can't think of any site i have done that i wouldn't want this.

Comments

greggles’s picture

Status: Active » Closed (won't fix)

As I read the code, it checks to see if the request is for a url like "node/something" but with no 3rd argument. It then checks to see if there is an alias for this node and, if not, it redirects you to the search page.

There are plenty of sites that use Pathauto and don't have aliases for all of their nodes. So, I don't think this will work in general.

Also, this code makes a lot of assumptions - it only works for anonymous users and it assumes search is enabled.

I suggest you investigate the Global Redirect module: http://drupal.org/project/globalredirect which does some things similar to this and a bit more.

liquidcms’s picture

yea, didn't think response for this would be over-whelming.. and odd.. since i will now do it on every site i do and it does seem like an obvious addition to pathauto. No problem that you won't add; but maybe a bit more clarification.

i do use globalredirect which "... will do a 301 redirect for all nodes which have an alias but are not using that alias." does not do anything like what i am referring to.

I do also have pathauto on (always, for every site) and also ALWAYS have nodes which i do not alias, but these are only nodes i never do full node view of. As i suggested before; pretty sure no decent web designer would ever have a path that looks like node/3456.

Also, as for search, were i to add this feature, i would provide a "default path" setting that the user could set as the "no alias defined so redirect here" path.

the no 3rd arg and for anon only were just quick/dirty way for admins to still be able to edit those nodes; better solution would likely be a perm like "access non-aliased nodes".

thanks for listening.. i guess easy enough to make this a separate module - just seemed overkill for adding 8 lines.