[wp-trac] [WordPress Trac] #40465: Multisite fails to rewrite upload path on main site

WordPress Trac noreply at wordpress.org
Sun Apr 16 22:28:54 UTC 2017


#40465: Multisite fails to rewrite upload path on main site
--------------------------------+------------------------------
 Reporter:  daniel berhane      |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Networks and Sites  |     Version:  4.7.3
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------------

Comment (by daniel berhane):

 Thanks John.
 I will try to be as detailed as possible.

 Note: The site was installed as multisite from the beginning, with WP
 version 3.7 and in its own directory. It is WPMU with subsites, not
 subdomain.

 Steps taken to switch subsite2 to a main site (since last week):

 '''1/ Changed Site Address (URL)''' in /wp-admin/network/site-info.php of
 the main site and subsite2

 {{{
 subsite1 domain.com/new/
 subsite2 domain.com/
 }}}

 '''2/ Changed blog id in wp-config.php.'''

 {{{
 define('BLOG_ID_CURRENT_SITE', 2);
 }}}

 '''3/ Search and replace urls in database'''
 Conducted search and replace using wp-cli:

 {{{
 wp search-replace 'domain.com' 'domain.com/new' wp_posts wp_postmeta
 --skip-columns=guid
 wp search-replace 'domain.com/subsite2' 'domain.com' wp_2_posts
 wp_2_postmeta --skip-columns=guid
 }}}

 '''4/ Sql dump'''
 The next day I noticed the image gallery is broken (images not visible
 inside gallery). The images don't load along the post, just their caption.
 But when you click on the link embedded in the captions and open in a new
 tab, the image loads.
 So I created sql dump using Search & Replace plugin by Inpsyde GmbH to
 make the following replacements:

 {{{
 Replace 'http://domain.com/wp-content/uploads/sites/2/' with
 'http://domain.com/wp-content/uploads/') in wp_2_posts post_content and
 wp_2_postmeta.
 }}}

 The image issue wasn't resolved.

 '''5/ Removed blog slug'''
 All along, the /blog/ slug wasn't appearing on links.
 Then, I figured ''siteurl'' in ''wp_options'' and ''wp_2_options'' needs
 to be manually adjusted. Thus, I changed like this:

 {{{
 wp_options siteurl domain.com/new
 wp_2_options siteurl domain.com/subdirectory
 }}}

 '''6/All posts of main site turned into 404.'''
 I can see the posts inside Posts Screen, but when I click the frontend
 /blog/ is automatically inserted/forced, thus leading to 404.
 So, taking a hint from ticket #12002, I checked on /site-settings.php
 permalink structure. Both subsite1 and subsite2 were set to
 /blog/%year%/%monthnum%/%day%/%postname%/
 I didn't check subsite1 until that point, but subsite2 permalink structure
 was set to /%year%/%monthnum%/%day%/%postname%/ until I changed
 ''wp_2_options siteurl'' on step 5.
 Since that ticket says it's okay to remove /blog/, i removed it on site-
 settings.php

 '''7/The posts of the main site''' became available at
 domain.com/%year%/%monthnum%/%day%/%postname%/
 Until that time, subsite1(old main site) was acting as a clone of
 subsite2(new main site), listing all the posts of the later. Even if it
 was deactivated and archived. But now, it started listing only its own
 posts.

 '''8/ Comparing the database with''' the backed-up database, I figured
 that at one of the earlier steps I should not have changed some urls that
 begin with domain.com/subdirectory/.... I also figured some urls that
 begin with domain.com/subsite2/ should have been changed to
 domain.com/subdirectory/..... rather than to domain.com. The urls point to
 plugin, wp-admin, etc. I fixed those using the interconnectit Search-
 Replace script.

 '''9/ Moving image files'''
 I had the webhost staff copy the folders of public_html/subdirectory/wp-
 content/uploads/sites/2/ to public_html/subdirectory/wp-content/uploads/.
 Now, image gallery started displaying images.

 '''10/ After two days,''' I noticed problem in other subsites' image
 galleries. All images were broken. Perhaps, the problem started earlier.
 But sometime around step 5 or 6, the file urls of those subsites were
 transformed to /subsite3/files/yyyy/mm/image-title.jpg. I guessed the time
 based on 404 reports log.
 A folder named blogs.dir was automatically created. Even if I deleted it,
 it's automatically created when image is added to a subsite.

 So, I deleted all plugins and themes. And added a line into wp-config.php.

 {{{
 /** Absolute path to the WordPress directory. */
 if ( !defined('ABSPATH') )
         define('ABSPATH', dirname(__FILE__) . '/');
 /** Sets up WordPress vars and included files. */
 require_once(ABSPATH . 'wp-settings.php');
 '''define( 'UPLOADS', 'wp-content/uploads' );'''
 }}}


 Now, everything is alright. Except the images of main site:
 Image gallery is okay. Post content okay.
 However, image url are set as: domain.com/subdirectory/uploads/yyyy/mm
 /image-title.jpg
 But they are also accessible at domain.com/ uploads/yyyy/mm/image-
 title.jpg
 Even if I stripped /subdirectory/ from the using the interconnectit
 script, they merely became custom urls of the images. File url is still
 domain.com/subdirectory/uploads/yyyy/mm/image-title.jpg on new image
 uploads.

 I don't mind the subdirectory/ on image urls. But it seems a symptom of
 another problem.
 Plus, the images of the main site can be accessed through two urls. Not
 good.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40465#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list