Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multisite support #1

Open
pdclark opened this issue Jun 5, 2013 · 2 comments
Open

Multisite support #1

pdclark opened this issue Jun 5, 2013 · 2 comments

Comments

@pdclark
Copy link
Owner

pdclark commented Jun 5, 2013

Multisite support basically comes down to three things:

The allowed path filter

class-404-template.php#L92
UBP checks to see if the requested $path from $_SERVER['REQUEST_URI'] contains $uploads['basedir'] with ABSPATH stripped out. So, for example, when requesting an image:

/wp-content/uploads/2012/10/image.jpg

$uploads['basedir'] without ABSPATH on a single site is:
wp-content/uploads
which exists in the requested path, so it passes.

On multisite, the requested $path would be:
/files/2012/10/image.jpg

But $uploads['basedir'] would be something like:
/wp-content/blogs.dir/3/files/ (where "3" is a blog ID)

So they don't match up. The check needs to be revised to accomidate multisite uploads directory path rewrites.

Download Path

class-404-template.php#L41
When an image is found, it's downloaded and saved to the local uploads directory. The download method, like allow_path, makes the assumption that the path to save the image to matches the path the image was requested from. In multisite, this isn't the case.

For example, single site:
image requested from: http://site.com/wp-content/uploads/2012/10/image.jpg
image saved to: ABSPATH.'/wp-content/uploads/2012/10/image.jpg'

But multisite:
image requested from: http://site.com/subsite/wp-content/uploads/2012/10/image.jpg
image saved to: ABSPATH.'/wp-content/blogs.dir/3/files/2012/10/image.jpg'

And "subsite" could also be a subdomain (subsite.site.com), or a mapped domain name. (subsite.com)

*Changes in 3.5 *

Trac ticket #19235

I haven't tested Nacin's final version of this in the 3.5 betas, but I'm pretty sure it's slated for release. Basically, in 3.5, there they'll be using wp-content/uploads/sites instead of wp-content/blogs.dir. wp_upload_dir() should account for this, but it of course needs to be tested, and the solutions for #1 and #2 need to be agnostic to whether they're running on 3.4- or 3.5+

To test any of these, you'd need to comment out the hook for requiring multisite to activate. But maybe you already did that? I was surprised to hear you activated the plugin on a multisite at all. Did it let you do it on the master site?

@Dreamsorcerer
Copy link

This seems to be working correctly for us on a multisite. The only thing that needed to be changed was the server rewriterule in the config/htaccess.

The default WP .htaccess has this:
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
Which essentially rewrites the path to strip out the subdirectory. The problem with this, is that when the file doesn't exist and it falls through to index.php the REQUEST_URI is still the original path. To solve this, change [L] to [P] which will perform a proxy redirect and use the rewritten URI instead. Note, you'll need to enable mod_proxy_http for this to work correctly.

Given that is all I needed to do to fix multisite support, can we replace the fail message with an admin notice that can instead give some tips on how to set it up?

@Dreamsorcerer
Copy link

Dreamsorcerer commented May 10, 2017

My actual rules in a <Directory> block as part of a VirtualHost, in case anybody has any trouble (this has actually been tweaked to work with multisites that use multiple levels of subdirectories).

<IfModule mod_rewrite.c>
    RewriteEngine On

    # add a trailing slash to /wp-admin
    RewriteRule ^(.*/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule "/.+(/(wp-content|wp-admin|wp-includes|.*\.php$).*)" $1 [P]
    RewriteRule ^ /index.php [L]
</IfModule>

If you have SSL enabled, you'll also need to add to your SSL section:

SSLProxyEngine on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants