Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How can users be prevented from accessing direct page URLs, requiring them to go through the alias? For example, 'node/5' should appear as a 404 error, but 'alias-to/fifth-node', which is aliased to that same 'node/5', would return the page. (I currently have the globalredirect and pathauto modules, but don't see any such features there.)
I'm not sure but I think I could use Apache URL rewriting to achieve this effect (right?), but if there's a way to do it in Drupal that'd be better for various reasons like customization, etc... Is this possible?
Comments
Comment #1
alex.skrypnyksubscribing
Comment #2
el_topo CreditAttribution: el_topo commentedI had the same problem, and sorted out by adding custom_url_rewrite_inbound() to settings.php.
This method is better than Apache rewrite rules, as it let you prevent access to node pages depending on user authentication status, or any other condition you may want.
You will also get a nice 404 error in drupal reports page every time someone tries to access a node directly and the message will include which was the original page entered (as notfound_node/11)
The reason why I let the admin user to access node/x pages, is that he's the one that will edit pages, and for that task he needs to access node/xx/edit.
My settings.php file has the following function:
I'm not a Drupal expert but I think this works well. Hope it helps.
Comment #3
el_topo CreditAttribution: el_topo commentedComment #4
VicOnt CreditAttribution: VicOnt commentedGood module:
https://www.drupal.org/project/access_filter
allows deny from node/n with a +B:Blind key that means will let through aliases