Trying to set up a WordPress Multisite using CloudFlare on individual blogs? I was. I just moved a WordPress (WP) Multisite subdomain installation and wanted to take full advantage of CloudFlare CDN for each for each of the sites blogs. It’s an awesome service, and free!
Using the lazy route of enabling CloudFlare on my domains via hosting control panel, it requires the www domain name prefix to invoke it’s magic. But the file uploads in a WordPress multisite don’t automatically include this magic.
By default, media uploaded through WP uses the path http://subblog.primaryblogdomain.com – we want to change that to http://www.blogname.com to be served up by CloudFlare.
How-to Instructions for setting up WordPress Multisite Using CloudFlare
In the WP backend (as Super Admin), on the toolbar, go to My Sites/Network Admin/Sites
Edit each site that has been set up on CloudFlare, and select the “Settings” tab.
Change the “site URL” field to be your fully qualified CloudFlare domain, as in http://www.blogname.com and note the blog ID number, from URL when you’re editing each blog. It will end with “site-settings.php?id=X” and we’ll make use of it shortly.
Test an upload to see it uses the proper url. Boom, it’s set!
If you are doing this on an installation that has been moved (i.e. already has posts), you’ll also need to update the posts table in the database. I like to use PHPmyAdmin for this. Hint: Backups are your friend!
Here is the query you’re looking at, where “X” is the ID of the wordpress blog if your tables are named named as mine are; you can easily identify each blog’s ID
UPDATE wp_X_posts SET post_content = replace(post_content, 'subblog.primaryblogdomain.com/wp-content/uploads/', 'www.subblog.com/wp-content/uploads/');
I would suggest leaving the upload path in the SQL command so you don’t inadvertently change something you didn’t want to change. Also, be sure it’s a correct upload path for your setup!
After you’re done, you can also add the CloudFlare WordPress plugin to see to it your stats and so forth accurately reflect your visitors’ locations. You will need to configure the plugin on each site of your installation individually.
I found I also needed to re-save my permalinks in some cases. I’m not sure if it was this operation that created the need or not. I was doing a lot of work on my install at the time, but if you’re getting 404 errors with post titles, give that a try.
That’s it–configuring Wordpress Multisite Using CloudFlare is not so difficult. Unless you have some image paths hard-coded in your themes, plugin or widget code, your WordPress should now serve all your images from Cloudflare instead of the local server. No plugins, no headaches. Just a little configuration change and some mySQL voodoo.
FYI, this information is offered AS IS, in the hopes it is of help to someone. If you break your Wordpress, I cannot fix it for you. I cannot answer WP support questions. This is what worked for me, period. Thanks for understanding.