Clean URL's in Nginx
Published: November 07, 2010
Quick post to let everyone know of a good trick I just figured out. Most clean URL's are created through a rewrite and query page that does all the work. Sometimes though you just want to have a couple php scripts that you can link to like https://oldstatic.travisberry.com/example
In Apache this is trivial. In Nginx, you can spend a couple days trying to get right.
Turns out the solution is simple. If you use a block of code like this
to turn on PHP, just replace the location with
and comment out
Your code block should now look like
Now instead of linking to /example.php, you can save the file with no extension, put it on your server, and link to /example
Nginx will now handle files without and extension as PHP files. This is a solution that will only fit a limited number of use cases, but compared to writing a rewrite wrapper, this is quick and easy.