How To

Moving Your Images For MultiSite (Updated)

When you move from Single WordPress to MultiSite, you can leave your images where they are, or you can move them to the new structure.

Updated after Andrew Nacin asked me “Why are you suggesting they replace ‘wp-content/blogs.dir/1/files/’ into their post content, instead of /files/?” (Answer: Because when I did this on my first site, about a year ago, I majorly goofed my SQL search/replace and shot myself in the foot For some reason, that made me think ‘files is bad! Blogs.dir is good!’ which … it’s not. Really, blogs.dir is fewer redirects, but that’s really about all I can say. So this has been edited. Thanks!)

In generic WordPress single installs, your images are, by default, located in a folder called uploads off the wp-content folder, and tend to look like this: wp-content/uploads/YYYY/MM/image.jpg. When you use MultiSite WordPress, the files are now in wp-content/blogs.dir/#/files (where the # is the blog number). If you upgrade from Single to MultiSite, you can leave the files for Blog #1, i.e. your primary blog, where they are to no ill effects. Or you can move them.

I’m not going to be using # as a placeholder, as for most people this blog will be 1. If for ANY REASON yours is not, change it.

Also, I can’t stress this enough, you don’t have to do this! Your images will be just fine where they are, but if you want to move them, you can. Enough people have asked on the support forums that I bothered to consolidate my notes on this, however.

Oh, and backup. Always backup before you start this sort of thing, otherwise you’re a reckless fool.

Step 1 – Move the OLD files

This is easy. Copy or move the files to wp-content/blogs.dir/1/files

While you’re in there, remember to set the folder writable so you can update files later. Your images will now look like wp-content/blogs.dir/1/files/YYYY/MM/image.jpg – Make a note of this, you’ll need it in a second.

Step 2 – Teach WordPress where the OLD files are

There are two main ways to do this:

Edit the Database
If you have phpMyAdmin or are savvy at command line SQL, just go ahead and run the replace command:

update wp_posts set post_content = replace(post_content, 'wp-content/uploads/', 'files/');

Now someone here might go “Hang on, I put my files in blogs.dir/1/files and you’re saying to tell WordPress to look in files! What gives?” What gives is what Andrew reminded me! WordPress MultiSite parses files from ‘files.’ The shortest explanation is ‘It’s an .htaccess trick.’ The longer explanation is it’s own blog post.

If you don’t like the idea of SQL, get a search and replace plugin like Search and Replace or Search RegEx and install it. Then search for wp-content/uploads/ and replace with wp-content/files/ to change the database.

In both database cases, you’ll want to check changes all over the place. For wp_posts, check post_excerpt and post_content, and then go through wp_postmeta and edit the meta_value fields.

That’s a lot of work, and odds are you’re still going to miss something. You can also be really lazy and add this to your .htaccess file, before the WordPress stuff:

# Moved Images
RewriteRule ^wp-content/uploads/(.*)$$1 [L,R=301]

That redirects things quietly. It’s probably not the best way, but like I said, I’m lazy. If I was doing this for a client, I’d probably do both the database fix and the .htaccess, to catch any stragglers.

Step 3 – Tell WordPress where to put the NEW files

Now the fun part! Go to your site’s wp-admin section, click on Super Admin and pick sites from the drop down. Hover your mouse just below the path to your main blog and click on Edit

In that new screen, scroll down and look on the left for Upload Path – You want to change that to wp-content/blogs.dir/1/files

You also want to change Fileupload Url to be (this will hold true even if you’re using subfolders or subdomains).

If you see Upload Url Path, you can change if to as well, though it appears to be depreciated and no longer used.

Step 4 – There is no Step 4

That’s it! You’re done!

5 replies on “Moving Your Images For MultiSite (Updated)”

Edited after Andrew Nacin asked me “Why are you suggesting they replace ‘wp-content/blogs.dir/1/files/’ into their post content, instead of /files/?”

He’s right! Why was I saying that? Because I remembered a bad SQL search/replace that buggered my site.

I shouldn’t have to tell you to backup before you do this, but backup.

It was … on the saved cache. Epic fail 🙂 Good catches. All fixed. Cache rebooted.

What if I were going the other way, moving from a MU site to a stand-alone single WordPress? Would I change the code to this:

replace(post_content, 'wp-content/blogs.dir/1/files/', 'uploads/');

In theory, yeah, though back up at the top of this post I said you don’t HAVE to do it? You shouldn’t have to do it if you revert from MultiSite (not MU – MU is pre v3.0 of WordPress), then your settings should be preserved.

But yes, you should be able to just move your content directory per usual.

If I was reverting from MultiSite back to Single, I’d probably export and import, personally. There’s a LOT of database cruft to clean up, and if I ever wanted to multisite it up again, it’d be a pain.

Comments are closed.

%d bloggers like this: