---
title: "Front Controller Patterns and nginx"
date: 2010-08-20
canonical: https://michaelshadle.com/2010/08/20/front-controller-patterns-and-nginx
---

# Front Controller Patterns and nginx

It's no secret I'm a fan of [nginx](http://nginx.org/). Probably no secret that I'm a fan of [front controller pattern](http://en.wikipedia.org/wiki/Front_Controller_pattern) design as well.

Why? I find it to be the most universal and easy to support. I create things from scratch using it, and the most popular software out there uses it - [Drupal](http://drupal.org/), [Joomla](http://www.joomla.org/), [WordPress](http://wordpress.org/) - and frameworks including the [Zend Framework](http://framework.zend.com/).

A lot of people cook up crazy nginx configurations for this stuff, when all it really takes for at least a standard setup is a single line of configuration code. However, I just found out something that was sitting in front of me this entire time.

BAD: I used to advise people to use this:

```
try_files $uri $uri/ /index.php?page=$uri$is_args$args;
```

BETTER: When actually, even simpler, you can use this:

```
try_files $uri $uri/ /index.php?page=$request_uri;
```

So my whole blog post [here](http://michaelshadle.com/2009/05/15/dont-forget-the-args) is slightly wrong. If you use $request_uri, you don't have to remember the $args. It's already there. :)

Note: different packages have different parameters. [CMS Made Simple](http://www.cmsmadesimple.org/) uses "page", Drupal uses "q", WordPress uses "q" - some software, like WordPress, doesn't technically need anything, they can fall back by reading PATH_INFO or REQUEST_URI, and not a parameter.

In which case, all you need is:

```
try_files $uri $uri/ /index.php;
```

Don't care about directories? Drop the "$uri/" too. Save some stat calls - if you don't need em :)
