Wordpress is written with the assumption that it will be hosted using Apache. This is mostly OK except for when it comes to URL rewriting, where the assumption that .htaccess
is all that’s required breaks down. In order to get permalinks working, you’ll need to add this to your nginx.conf
for the site concerned:
# Rewrite rules for pretty urls
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?q=$1 last;
}
This catches any missing files and rewrites the request to pass the requested page as a param to index.php
, which is how the permalinks are supposed to work.
The code assumes your blog is hosted at the root of your domain. If your blog resides within a subdirectory, you’ll need to use something like this instead: