I have created a new content type for which I am using pathauto to created aliased urls for. I would like to prevent access to the node via the /node/ url for just this content type. Users would have use the alias url instead to access the node.

I have attempted to search for any past work in this area but I have not found anything. Does anyone know if this is possible?

Comments

yelvington’s picture

There are many contributed modules that provide similar functionality. The best choice depends on the specifics of what you're trying to do. See http://drupal.org/project/content_access and other related modules in the http://drupal.org/project/Modules/category/74 list.

AcidReflux’s picture

I'm not sure these give me what I want. I took a look through the entire list and any access control talks about access to the node in general. In my situation I would have two urls to access a node:

1. /node/1
2. /my/custom/url

For a specific node type I want to prevent access via #1 and only allow access via #2.

None of the modules in that category appear to operate on that level, but instead focus on node access control. In this case it would deny both #1 and #2.

The global redirect module provides functionality almost the way I want. If a user accesses #1 they are redirected to #2. For this node type I don't want that to happen (all other node types this behavior is fine). Instead reporting 404 or 403 would be nice.

apsivam’s picture

AcidReflux’s picture

See my comment above. The global redirect module would redirect every /node/ url. In my case, for a specific content type I don't want this.

apsivam’s picture

Then you need to hack Global Redirect module to cater your need. Not everything in life comes in boxed packing.

--
Cheers,
Sivanandhan, P. (a.k.a. apsivam)

AcidReflux’s picture

Understood. I just don't want to reinvent the wheel if someone has already done this :)

amitaibu’s picture

Hi,
I was looking for the same thing, since I'm building my site with panels.
Here is a solution for your needs - Workflow-ng, though right now there is a small bug there. But it will be possible (the module is being fixed very quickly).

Note, that for anonymous users, for this to work, you will need to disable page cache.

---
gizra.com - where cool software developers meet geek fashion designers

AcidReflux’s picture

Hmmm, interesting module. Although I'm not sure I like the restriction for anonymous users and the page cache. But I'll poke around.

amitaibu’s picture

So far as a non-developer that is the only way I found.
---
gizra.com - where cool software developers meet geek fashion designers

AcidReflux’s picture

I hacked up Global Redirect to do what I wanted. It's not a 100% clean hack, but it was relatively simple. Thanks for the pointer, that module might come in handy later.

amitaibu’s picture

Hi,
Since I and probably other also need something similar, can you share the info with us? Maybe even better create a patch against GlobalRedirect module.
---
gizra.com - where cool software developers meet geek fashion designers

AcidReflux’s picture

I don't think I can easily create a patch, but here's the code I added (with some context before and after). You'll want to replace contenttype with the machine readable name of the content type you want to enable this for. This is where you can see what a hack it is. Ideally there would be a configuration page with a list of your content types to enable this for.

At a basic level the first if looks for urls of the node/ format and makes sure there is no query string (edit, delete, etc). I then look up the node id in the db and check it's type. I then redirect the user to the homepage with a 404. It would be better to send them to the official 404 page, but so far I haven't found the correct method to do this.

    // Get the request string (minus trailing slash e.g. node/123/)
    $request = preg_replace('/\/$/', '', $_REQUEST['q']);

    if (preg_match('/^node\/([0-9]+)$/',$request,$matches)==1 && $query_string == "")
    {
        $node = node_load($matches[1], NULL, TRUE);
	  if ($node->type == "contenttype")
	  {
	        drupal_goto("/","",NULL,404);
	  }

    }
    
    // Check the path (eg, node/123) for an alias. If one is found, redirect.
pol’s picture

Hello,

I made a module based on your script.

I needed it in a project. I'm planning to improve it !

You can find it here: http://github.com/Polzme/AOA

Any improvements is, of course, welcome !

jobjol’s picture

I had a similar issue. All the nodes on my websites are being created by anonymous users.
Still i want to keep those nodes private for those anonymous users.

There is a simple htaccess rule to make this possible in combination with "Extended path aliases".

# Redirect all node nid paths
RewriteRule ^node/[0-9]+$ http://accessdenied.com [R=301,L]

Read more @ http://jobjol.nl/notes/preventing-access-nodenid-paths-htaccess

pol’s picture

Very good idea too ! Thanks for sharing !