$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>htaccess - Moving a WP Multisite to a subdirectory|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

htaccess - Moving a WP Multisite to a subdirectory

matteradmin9PV0评论

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 to root/blogs?

For this example, we're moving a WPMS from "root" to "root/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    | /      |
|       2 | root    | /matt/ |
+---------+-------------+--------+

2. wp_site

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

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        | /    |
| siteurl     | /    |
+-------------+--------------------------+

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' );
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    | /blogs/      |
|       2 | root    | /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    | /blogs/    |
+----+-------------+------------+

3. wp_#_options

+-------------+--------------------------------+
| option_name | option_value                   |
+-------------+--------------------------------+
| home        | /    |
| siteurl     | /    |
+-------------+--------------------------------+

4. wp_config.php

define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false);
$base = '/blogs/';
define( 'DOMAIN_CURRENT_SITE', 'root' );
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 to root/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 / you should. It's excellent.

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 to root/blogs?

For this example, we're moving a WPMS from "root" to "root/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    | /      |
|       2 | root    | /matt/ |
+---------+-------------+--------+

2. wp_site

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

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/matt/    |
| siteurl     | http://root/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' );
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    | /blogs/      |
|       2 | root    | /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    | /blogs/    |
+----+-------------+------------+

3. wp_#_options

+-------------+--------------------------------+
| option_name | option_value                   |
+-------------+--------------------------------+
| home        | http://root/blogs/matt/    |
| siteurl     | http://root/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' );
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 to root/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/products/search-and-replace-for-wordpress-databases/ you should. It's excellent.

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Dec 21, 2012 at 19:28 ScreenackScreenack 3211 gold badge2 silver badges6 bronze badges 3
  • 3 Great question, great process +1 – kaiser Commented Feb 10, 2013 at 12:19
  • 2 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 Commented Dec 2, 2015 at 18:50
  • Works. In /wp-admin first looks is broken because the scripts/css dont load, but I solved putting define('CONCATENATE_SCRIPTS', false); in wp-config.php – nicogaldo Commented Mar 2, 2022 at 22:42
Add a comment  | 

5 Answers 5

Reset to default 8

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)

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.

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'); // 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/blogname

2) wp_blogs for each blog_id change the domain from blogname.domain to domain 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!

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 path: /

wp_blogs domain: xyzabc path: /

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

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

Rewrite your wp-config.php with this code

define('SUBDOMAIN_INSTALL', false);

instead of define('SUBDOMAIN_INSTALL', true);

then goto:

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

then:

Add the following to your .htaccess file in /var/www/vhosts/website/, 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

Post a comment

comment list (0)

  1. No comments so far