# Try\_files question or alternative?

**URL:** <https://www.ruby-forum.com/t/try-files-question-or-alternative/235370>\
**Category:** NGINX\
**Created:** [June 18, 2013, 12:06am UTC](https://www.ruby-forum.com/t/try-files-question-or-alternative/235370 "2013-06-18T00:06:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [June 18, 2013, 12:06am UTC](https://www.ruby-forum.com/t/try-files-question-or-alternative/235370/1 "2013-06-18T00:06:02Z")

</div>

Is there a simple way of getting nginx to search for the index when  
given a bare directory as URL?

eg in a server block…

index index.php index.html index.htm;

when passed an URL of [http://www.example.com/sub](http://www.example.com/sub) where there is no

location /sub {} block

it looks for [http://www.example.com/sub/index.php](http://www.example.com/sub/index.php) etc…

Cheers,

Steve

–  
Steve H. BSc(Hons) MNZCS

> **[Linux & Admin Support Services | "Services provided by people who are...](https://www.greengecko.co.nz/)**
>
> Offers linux support services, systems and database administration, consultancy and the full development lifecycle for open source - based solutions

Linkedin: [http://www.linkedin.com/in/steveholdoway](http://www.linkedin.com/in/steveholdoway)  
Skype: sholdowa

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [June 18, 2013, 12:27am UTC](https://www.ruby-forum.com/t/try-files-question-or-alternative/235370/2 "2013-06-18T00:27:39Z")

</div>

On Tue, Jun 18, 2013 at 10:05:07AM +1200, Steve H. wrote:

Hi there,

> Is there a simple way of getting nginx to search for the index when  
> given a bare directory as URL?

In general, this is a bad idea. In your specific case, it may not be.

So if an explicit listing is acceptable, then you could try something  
like

location / {  
try\_files $uri $uri/index.php $uri/index.html $uri/ =404;  
}

with whatever surrounding extra configuration is needed.

But really, /sub and /sub/ are different urls, and you should have a  
good  
reason to not just use the defaults.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
