Pretty URLs with Nginx and Wordpress
I recently had to hack through a server and Wordpress to get permalinks to look good and function. Here’s my solution;
Found this answer on Stackoverflow:
add this and remove any non-specific rewrite rules:
try_files $uri $uri/ /index.php;
The only thing missing was where to put that line of code. This post pointed me to insert that line before the first location declaration.
Once I did that, then I restarted the Nginx daemon with:
sudo service nginx restart
The I went into the permalinks section of the Wordpress installation. The permalink setting I like is the “Post Name” setting. Choosing that radio button sets the url structure as:
/index.php/%postname%/
Unfortunately this setting still returns 404’s when you enter the structure of the site. I then chose the “Custom Structure” radio button and deleted the index section of the structure to get:
/%postname%/
Then you get happy pretty urls!