Somebody should really document that better.
Creating a rule set for nginx is a bit more complex than one for Apache and .htaccess, because nginx is slightly more complicated. The basic gist of it is that you want to redirect anything for a URL that doesn’t correspond to a real file on the system to the main index.php. So the rules for multisite aren’t actually any more complicated than the normal rules, except for the /network thing.
This is the basic multisite ruleset:
if (!-e $request_filename) {
rewrite ^/files(.*) /wp-includes/ms-files.php?file=$1 last;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*.php) $2 last;
rewrite ^.*$ /index.php last;
}
The first rule handles the ms-files thing for older installs. Not relevant on a new install.
The next two rules handle the /network urls, redirecting them to the main site properly.
The last rule redirects everything else to the index.php.
Also, note that these rules only apply for the !-e case, so calls to files that exist get handled by those files themselves.
Thnks otto. but as I also use wp domain mapping so will that snippet will be enough for my site? I mean the apache htaccess I posted and the code you given does the do the same thing? I didnt find any /network
think in your given nginx code.
Please take a look at my htaccess and please give me the code which will do the same in nginx. I really dont wanna break my site in nginx.
will this work good on subdomain based MU with domain mapping plugin installed?
The 6-line code I posted above (ignore the first one which I later deleted, bad copy/paste) is actually what I use myself for a multisite setup with domain mapping. It works fine for me.
I have a few extra rules that are specific to my own site, but those rules do the job for me. I use them to run ottodestruct.com and ottopress.com, where ottopress is just a mapped domain to the main multisite instance at ottodestruct.
Great but does your multisite network is subdomain based or directory based? Because from the http://codex.wordpress.org/Nginx it seem that sub directory based MU has different rules than sub domain based MU.
I’m using subdomain based MU.
Also thank you very much man for your helpful reply. If you think there are few other code is good to add on my nginx server so that it load faster and run smoother, please share that too 🙂
If you’re using domain mapping, then it actually doesn’t make a whole lot of difference whether you’re using subdirectory or subdomain based, because domain mapping overrides both.
The bottom line is that you want to direct the request to the main WordPress index.php file. How you get that to happen is the only thing that matters in your nginx configuration. Once the request makes it into WordPress, then WP takes over and determines what to display. What you need to do in your configuration is largely about making it route all requests for URLs that don’t map to existing file structures to the WordPress files.
OK. I will use your above code in my vps. Just hoe it will work fine like it working now 🙂
His is subfolder but he maps domains.
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*.php) $2 last;
That’s the subfolder part.
rewrite ^/files(.*) /wp-includes/ms-files.php?file=$1 last;
That’s for the files redirect, which you don’t need either.
I THINK the WordPress regular rules will work for Subdomains as they stand since looking at http://wiki.nginx.org/WordPress#Rewrite_rules_for_Multisite_using_subdomains it’s just adding in for the files folder, which you’re not using.
(Otto’s is so old he has define( 'VHOST', 'no' );
… it’s kinda cute)
The nginx wiki has a slightly different set of rules using the try_files method, which is arguably a better approach:
http://wiki.nginx.org/Wordpress#Rewrite_rules_for_Multisite_using_subdomains
In the long run, I think that the differences since the original MU setups and the core of WordPress have been mostly merged, and the same set of rules will apply to both most anywhere. You only need to get it working as normal single-site rules, and then handle special cases as special.
thanks but does this rule complies with domain mapping too? Then I will just copy paste that rule
No matter what set of rules you use, it’s unlikely to be a “copy/paste” operation. You can start off with some set of rules, and then later find an edge case for your specific setup that you will need to handle. Feel free to experiment and find what rules work for your case, and then modify them on an as needed basis.