18

Firstly, I've read a number of posts on this process. However, for various reasons, the process remains difficult to implement or troubleshoot for lack of even abstracted examples, or maybe too abstracted. And there's a few "can not do" posts, nearly always followed up by "with 3.5, you now can" caveats, so whether one can remains ambiguous, though no doubt non-trivial.

Summary:

How to move a wordpress multisite (WPMS) from root.com to root/blogs?

For this example, we're moving a WPMS from "root.com" to "root.com/blogs"

I understand that I need to update the paths in the database and wp-config.php appropriately. It seems I may also have to update .htaccess? I'm also aware of the serialization issue with search/replace and mysql query updates.

I have a WPMS that I've updated to 3.5. I've found the following tables with domain and path info

Existing working configuration before move to subdirectory

1. wp_blogs

select blog_id, domain, path from wp_blogs;
+---------+-------------+--------+
| blog_id | domain      | path   |
+---------+-------------+--------+
|       1 | root.com    | /      |
|       2 | root.com    | /matt/ |
+---------+-------------+--------+

2. wp_site

select * in wp_site;
+----+-------------+------+
| id | domain      | path |
+----+-------------+------+
|  1 | root.com    | /    |
+----+-------------+------+

3. The blog_id corresponds to the wp_#_options tables which contain:

select option_name,option_value from wp_2_options 
where option_name = 'home' or option_name = 'siteurl';
+-------------+--------------------------+
| option_name | option_value             |
+-------------+--------------------------+
| home        | http://root.com/matt/    |
| siteurl     | http://root.com/matt/    |
+-------------+--------------------------+

4. In my wp-config.php I have the following WPMS-specific lines:

define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false);
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'root.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

5. Lastly, in my .htaccess, I have:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

Updates required to move the site

It seems to me that in order to move my site to the /blogs , I would:

1. Update wp_blogs to

mysql> update wp_blogs set domain=concat(domain, '/blogs'), path=concat(path, 'blogs/');
select blog_id, domain, path from wp_blogs where blog_id < 3;
+---------+-------------+--------------+
| blog_id | domain      | path         |
+---------+-------------+--------------+
|       1 | root.com    | /blogs/      |
|       2 | root.com    | /blogs/matt/ |
+---------+-------------+--------------+

2. Update wp_site to

update wp_site set domain=concat(domain, '/blogs'), path=concat(path, 'blogs/');
select * from  wp_site;
+----+-------------+------------+
| id | domain      | path       |
+----+-------------+------------+
|  1 | root.com    | /blogs/    |
+----+-------------+------------+

3. wp_#_options

+-------------+--------------------------------+
| option_name | option_value                   |
+-------------+--------------------------------+
| home        | http://root.com/blogs/matt/    |
| siteurl     | http://root.com/blogs/matt/    |
+-------------+--------------------------------+

4. wp_config.php

define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false);
$base = '/blogs/';
define( 'DOMAIN_CURRENT_SITE', 'root.com' );
define( 'PATH_CURRENT_SITE', '/blogs/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

note: I'm not clear how this step is appropriately updated

5. .htaccess

I found vague "update .htaccess appropriately" instructions, but not specifics. Update RewriteBase? Which lines in .htaccess to I update when I move root.com to root.com/blogs?

Missing from the above process will be the paths founds in posts. My druthers are to use the search and replace tool for that, after I've made this more fundamental updates; or am I wrong?

Update bungeshea suggests that, yes, I point RewriteBase to the "blogs" subdirectory, i.e.,

RewriteBase /Blogs

Finally, if you don't know about http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ you should. It's excellent.

  • 3
    Great question, great process +1 – kaiser Feb 10 '13 at 12:19
  • 1
    Is it just me? I think, queries in the process are not correct update wp_blogs set domain=concat(domain, '/blogs'), path=concat(path, 'blogs/'); should rather be update wp_blogs set path=concat('/blogs',path); – M-R Dec 2 '15 at 18:50
5

I know it's old but I fixed it! i installed WP MU in a subfolder. htaccess:

RewriteEngine On
RewriteBase /YOUR_SUBFOLDER
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule ^(.*\.php)$ YOUR_SUBFOLDER/$1 [L]
RewriteRule . index.php [L]

wp-config.php:

define( 'WP_ALLOW_MULTISITE', true ); 
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost'); // or your host
define('PATH_CURRENT_SITE', '');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

and in your database, modify this:

wp_site
domain: localhost (OR your domain but no subdirectory!)
path: /

wp_blogs
domain: localhost (OR your domain but no subdirectory in each blog_id!)
path: /

wp_sitemeta
siteurl: http://localhost/YOUR_SUBFOLDER (replace localhost with your host)
  • this was incredibly helpful. I had a subdomain install and a database dump and zip of the site. I needed to restore it on a new server, and had to manually update the site. The database updates were the most imperative ones I needed to make. Thank you! – Jacob Raccuia Oct 13 '16 at 3:56
2

It looks to me as if you've solved your own problem - just follow your steps 1-4, and for step 5 update the RewriteBase in .htaccess. For updating the paths in posts, I like using the Interconnect IT sterilized search-and-replace tool.

  • Thanks, bungshea. As I indicate in my post, update RewriteBase to what, exactly, as per the above example? Would that be: RewriteBase /blog ? – Screenack Jan 2 '13 at 14:05
  • Yes: RewriteBase /blog – shea Jan 2 '13 at 21:41
  • Bungshea; done, but still not working. Still getting "Error establishing database connection" after all of the above. Worse, there's no errors thrown to my apache error log. – Screenack Jan 4 '13 at 17:10
  • @Screenack what are the specifics of "Error establishing database connection"? Hint: visit wp-admin – shea Sep 1 '13 at 6:30
1

Ok here's what I did and this worked. No sub_folder. Site was previously configured to subdomain.

BACKUP FIRST!!!

wp-config.php (replace this block with the block in your file)

define('WP_ALLOW_MULTISITE', true ); 
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'no-www-in-sitename.com'); // your host
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

now in the SQL DB:

1) for each wp_(site#)_tablesuffix go to the options table and change siteurl and home to http://www.sitename.com/blogname

2) wp_blogs for each blog_id change the domain from blogname.domain.com to domain.com and path to /blogname/

3) no need to change wp_options siteurl & home or any cells in wp_site or wp_sitemeta if the install is in the same location.

After you're done be sure to go to (in the superuser admin panel) settings > permalinks and click save.

Voila!

0

This is my first answer so please be considerate! :)

I DID NOT have a blog that already was in subdomains to be converted. But I had to fight because it was an old blog and they wont let me make a subdirectory blog and I feared that WP made changes to my DB by the time they gave me the codes to put in.

This is what worked for me in April 2018 guys ... I used the wp-config from hot_barbara and I used the .htaccess also from them.

Therefore, please dont go for a subfolder - I didnt!

HOWEVER, in SQL DB, this is what happened in my case - it was all already this way so I didnt make any changes:

  1. wp_site domain: xyzabc.com path: /

wp_blogs domain: xyzabc.com path: /

wp_sitemeta siteurl: h**ps://xyzabc.com/

You would - as I understand - be using a trailing slash if you had it in your settings.

0

Rewrite your wp-config.php with this code

define('SUBDOMAIN_INSTALL', false);

instead of define('SUBDOMAIN_INSTALL', true);

then goto:

http://www.website.com/wp-admin/network/setup.php

then:

Add the following to your .htaccess file in /var/www/vhosts/website.com/, replacing other WordPress rules:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

That's it.

Create a New Site with Subdirectory

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.