Reputation: 12653
I am building an automated WordPress deploy using Composer, and am keeping the wp-content folder outside of the main WP install (because I have some custom plugins and themes) which is pulled from github.
After pulling from github and running composer, my folder structure looks like:
-composer.php
-env.php
-public/
|-index.php
|-wp-config.php
|-wp-content/
|-themes/
|-plugins/
|-sunrise.php
|-wp/
|wordpress stuff
My htaccess rules work well when using MAMP, but I am using VVV as my development environment and VVV uses nginx, so my rewrite rules don't work.
VVV uses 2 conf files: one file thats shared by all sites on the VM (common rules) and one file for each site (basically just lists the root dir).
Here is my site specific conf file:
server {
listen 80;
listen 443 ssl;
server_name auto.dev ~^auto\.\d+\.\d+\.\d+\.\d+\.xip\.io$;
root /srv/www/auto/htdocs/wordpress;
# my rules
# tells nginx to prepend "wp" to things
rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
# end WP dir rules
include /etc/nginx/nginx-wp-common.conf;
}
so I added
rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
And that kind of works (I am able to get the the admin area, and the admin area has all of its CSS and JS), but I am facing 3 big problems:
1)The frontend of the site no longer has its CSS. Chrome's console shows an error on the second line of my index.php:
Uncaught SyntaxError: Unexpected token <
note - It looks like SOME of the themes work, a site with the Twenty Fifteen theme looks like it works.
2) I cannot get to the multisite network area, for whatever reason anytime I attempt to goto http://auto.dev/wp-admin/network/
my request is rewritten as: http://http//auto.dev/wp-admin/network/
and thus obviously doesn't work
3) Finally I cannot login to my subsites. Stuff like http://auto.dev/wiki/wp-admin/
gives me a redirect loop
4) I just noticed that when I try to change the theme for a site, the theme previews are broken.
Upvotes: 4
Views: 881
Reputation: 444
Consider a solution just with updated NGINX config, which I've published on github. Change your rewrites with following
if (!-e $request_filename) {
rewrite ^/(wp-admin/.*)$ /wp/$1 last;
rewrite ^/[_0-9a-zA-Z-]+(/wp-admin/.*)$ /wp/$1 last;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-includes/.*) /wp/$1 last;
rewrite ^/(wp-[^/]+\.php)$ /wp/$1 last;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
rewrite ^/(wp-includes/.*)$ /wp/$1 last;
That will solve all the problems with access to admin panels and the network admin panel with sub-folder installation of the Wordpress Multisite. No need code writing.
Upvotes: 0
Reputation: 11378
Just few notes:
Your wp-content/
folder isn't under the wp/
folder as you stated here:
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
Since default themes, like Twenty Fifteen come shipped with the /wp/wp-content/
folder, it could explain why you get it to work there.
Regarding the missing /wp/
part in the network admin urls, Daniel Bachhuber has posted this handy gist snippet that fixes that problem. It uses the network_site_url
filter to inject it.
<?php
/**
* Fix network admin URL to include the "/wp/" base
*
* @see https://core.trac.wordpress.org/ticket/23221
*/
add_filter( 'network_site_url', function( $url, $path, $scheme ){
$urls_to_fix = array(
'/wp-admin/network/',
'/wp-login.php',
'/wp-activate.php',
'/wp-signup.php',
);
foreach( $urls_to_fix as $maybe_fix_url ) {
$fixed_wp_url = '/wp' . $maybe_fix_url;
if ( false !== stripos( $url, $maybe_fix_url )
&& false === stripos( $url, $fixed_wp_url ) ) {
$url = str_replace( $maybe_fix_url, $fixed_wp_url, $url );
}
}
return $url;
}, 10, 3 );
Also see the open ticket #23221 on Multisite in subdirectory with root site address
Some discussions here on GitHub regarding nginx + multisite with wp-skeleton structure (I posted there some experiments some time ago).
Upvotes: 5