I have been testing running my site with Nginx instead of Apache. One of the issues I have ran across is getting wordpress to work right since I use the SEO urls. Not that SEO urls make any difference, its a fun challenge to just work with.
One issue I ran across is getting these urls to work right. After some reading, I did discover that there is a simple code for the rewrite that is used in apache. However I couldn’t get this to work as the document examples showed. I found out after testing, that it must exist in the location attribute. Which is actually better for the setup.
location / {
root /home/sites/sleepycode.com/public_html;
index index.php index.html index.htm;
# Send a expire header for static files.
if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)\?[A-Za-z0-9\.-_]+$")
{
expires 30d;
break;
}
# Handle wordpress pretty urls.
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
This makes things work as they should.
Update:
If has been suggested by the Nginx team to be avoided. So here is another solution that avoids if:
# Handle wordpress pretty urls.
location /
{
try_files $uri @wordpress;
}
location @wordpress
{
rewrite "^/(\d{4})/(\d{2})/(.+)$" /index.php?q=$1 last;
}
