# Path to a directory should return 404

**URL:** <https://www.ruby-forum.com/t/path-to-a-directory-should-return-404/213645>\
**Category:** NGINX\
**Created:** [November 7, 2011, 11:23pm UTC](https://www.ruby-forum.com/t/path-to-a-directory-should-return-404/213645 "2011-11-07T23:23:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 7, 2011, 11:23pm UTC](https://www.ruby-forum.com/t/path-to-a-directory-should-return-404/213645/1 "2011-11-07T23:23:06Z")

</div>

Under the document root, I have few directories like  
/1/file1.html  
/1/file2.html  
/2/file1.html  
/2/file2.html

If I go to the url [http://localhost:8080/1](http://localhost:8080/1), I get back a 301 with the  
new location [http://localhost/1/](http://localhost/1/) autoindexing is off, and so I end  
up with a 403 Forbidden page.

Can I change this default behavior such that all the requests for the  
directories get the universal 404 page i.e. instead of a redirection, it  
should simply return the configured 404 page for location /.

Sorry, I couldn’t find a similar post on the forums. Thanks for any  
pointers.

Posted at Nginx Forum:

> **[Path to a directory should return 404](https://forum.nginx.org/read.php?2,217950,217950#msg-217950)**
>
> Under the document root, I have few directories like \<root\>/1/file1.html \<root\>/1/file2.html \<root\>/2/file1.html \<root\>/2/file2.html If I go to the url http://localhost:8080/1, I get back a 301 with the new location...

---

<div class="post-metadata">

**Author:** ![nchainani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@nchainani](https://www.ruby-forum.com/u/nchainani)\
**Post date:** [November 8, 2011, 9:31am UTC](https://www.ruby-forum.com/t/path-to-a-directory-should-return-404/213645/2 "2011-11-08T09:31:11Z")

</div>

On Mon, Nov 07, 2011 at 05:22:29PM -0500, nchainani wrote:

> Can I change this default behavior such that all the requests for the  
> directories get the universal 404 page i.e. instead of a redirection, it  
> should simply return the configured 404 page for location /.
> 
> Sorry, I couldn’t find a similar post on the forums. Thanks for any  
> pointers.

Something like that maybe?

: location / {  
: #error\_page 404 …;  
: location ~ /$ { return 404; }  
: }
