I'm currently using the Redirect module in Drupal 8 along with Pathauto to create aliases on all url's. So for example /node/23 would be /article/some-text-here. When a user types in /node/23 in the url it automatically redirects them to the alias url. I want to show a 404 whenever the user uses the node path url instead of redirecting that way they don't ever have a chance to find something they shouldn't by traversing through my site with that pattern.

3 Answers 3


The rabbit_hole module can be used to set 'access' controls for rendered nodes, taxonomies, and other entities. When a user visits the /node/* or /taxonomy/term/* page, you can control what happens--403 page, 404 page, redirect, whatever. This can also be overridden on a per-node basis if you require that.


This still allows the entities to be accessible via path alias and shouldn't break any references to those nodes/taxonomies.


Make sure apache mod_alias is enabled and create a rule in .htaccess like:

Redirect 404 /node/.*$ 
  • this had no effect. I tried RewriteRule ^/?node/[^a-zA-Z_]+$ redir_path [L,R=301] and it worked but I want to display the 404 instead of redirecting.
    – klo009
    Feb 16, 2017 at 21:43

I would also try this, although this would apply for Drupal 7

$path = current_path();
if($path == 'node/23') {
  • This is not a good answer - original question is asking for a scalable solution, not hardcoded. Also, this won't work for Drupal 8.
    – Kevin
    Feb 17, 2017 at 14:54
  • I have made an edit as to suggest for drupal 7.
    – ShanjayG
    Feb 18, 2017 at 0:53

Your Answer

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

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