# Index.php in folders

**URL:** <https://www.ruby-forum.com/t/index-php-in-folders/245522>\
**Category:** NGINX\
**Created:** [June 7, 2013, 7:25am UTC](https://www.ruby-forum.com/t/index-php-in-folders/245522 "2013-06-07T07:25:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [June 7, 2013, 7:25am UTC](https://www.ruby-forum.com/t/index-php-in-folders/245522/1 "2013-06-07T07:25:24Z")

</div>

Is there a simple config I can use to check for an index.php in  
subfolders?

It was my understanding that if I used

index index.php;

in the server block, and

try\_files $uri $uri/ /index.php;

in location / {} that it would look for $uri/index.php. But I do seem to  
be misunderstanding.

Help!

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 7, 2013, 7:55am UTC](https://www.ruby-forum.com/t/index-php-in-folders/245522/2 "2013-06-07T07:55:47Z")

</div>

Hello,

On Fri, Jun 7, 2013 at 1:24 AM, Steve H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> in location / {} that it would look for $uri/index.php. But I do seem to  
> be misunderstanding.

​  
Your try\_files directive is only working if your content is served by  
the  
location block where it is placed.  
If another location block serves content, the try\_files directive won’t  
apply. I don’t know the default behavior then, but I guess that you  
either  
need to specify a directory by ending the URI with a trailing slash  
(directory) or specify the ‘index.php’ file at the end of it.

I suggest you move the try\_files directive up in the hierarchy, thus in  
the  
containing server block.  
​

> Help!

​  
I also suggest that you add something after the last part of the  
try\_files  
directive or replace it with a proper handler for missing files.  
In your example, you specified that requests missing files should be  
redirected to ‘/index.php’. That can end-up in a loop-hole if there is  
no  
index.php file at root.

I suggest you use something like:  
try\_files $uri $uri/ /index.php =404;

## Please read the documentation of the try\_files directive[http://nginx.org/en/docs/http/ngx\_http\_core\_module.html#try\_files](http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)for more information.​

_B. R._
