• Hi I’m planning for using a vps with nginx. Now I use a wp multisite 4.1 with wp domain mapping plugin on a lightspeed server so here is my htaccess rule:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    </IfModule>
    # END WordPress

    I’ve checked this page http://codex.wordpress.org/Nginx but it made me confused. On this link all code are given for sub-directory based wordpress mu, but I use subdomain based wordpress mu.
    As this is my production site I really wanna know which nginx code should I place on my server which will do the exact same thing as I posted above.

    Please help.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

    Thread Starter iSaumya

    (@isaumya)

    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.

    Thread Starter iSaumya

    (@isaumya)

    will this work good on subdomain based MU with domain mapping plugin installed?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

    Thread Starter iSaumya

    (@isaumya)

    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 🙂

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

    Thread Starter iSaumya

    (@isaumya)

    OK. I will use your above code in my vps. Just hoe it will work fine like it working now 🙂

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    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)

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

    Thread Starter iSaumya

    (@isaumya)

    thanks but does this rule complies with domain mapping too? Then I will just copy paste that rule

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘nginx code for wp multisite’ is closed to new replies.