Nginx location rule for Wordpress Multisite in subdirectories

Ian M. Evans ianevans at
Sun Aug 26 18:40:40 UTC 2012

Hi everyone!

I currently have a wordpress blog located at blogname and, as per threads
here, I had the following on my nginx.conf:

location ^~ /blogname {
  try_files $uri /blogname/index.php?q=$uri;
  location ~ \.php$ {


I'm actually adding a few more blogs and will be moving to the multisite
options in wordpress and running the various blogs in subdirectories under
/blogs, e.g.:


I need to be able to catch the above in either /blog or its suddirs, since
WP installs a main blog in the /blogs dir i.e.:

location ^~ /blogs {
  try_files $uri /blogs/index.php?q=$uri;


location ^~ /blogs/blog1 {
  try_files $uri /blogs/blog1/index.php?q=$uri;

I realize I could create locations specific to each dir, but is there a
wildcard way to do this?


p.s. as I've said before, my nickname should be "Sucks at regex"

More information about the nginx mailing list