1

I upgraded a Wordpress Multisite install from 4.9.15 to 5.9. and moved to a different hosting platform. On the subsites the images were not displaying and they were not attached on the upgrade. When I uploaded an image to one of the subsites media library, it would not display in the media library. I then took the old htaccess file from the 4.9.15 install and replaced the new htaccess file. After that I could upload to the media library and see the file within the subsites. Base site always worked. During the upgrade would the htaccess file be overwritten ?

I looked at a different multisite install on another site and it looks like uploads for each site are stored in separate folders. This is not the case for the site in question, the one I upgraded. All subsites seem to share the same main uploads folder. Was this the case with old versions of multisites ? And newer versions of WP multisite have different folders for different subsites ?

Below is the code from the htaccess file from the 4.9.15 site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
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]

</IfModule>

# END WordPress
# Disallow access to the WP readme that contains the WP version
RedirectMatch 404 /readme.html$

# Disallow access to .git files
RedirectMatch 404 /\\.git.*(/|$)
RedirectMatch 404 /\\.git/.*(/|$)

# Disallow access to capistrano revision file
RedirectMatch 404 /REVISION(/|$)

ErrorDocument 404 /404.php

# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

# disable the server signature
    ServerSignature Off

# limit file uploads to 10mb
    LimitRequestBody 10240000

# protect wpconfig.php
    <files wp-config.php>
    order allow,deny
    deny from all
    </files>

#who has access who doesnt
    order allow,deny
    
#deny from 000.000.000.000
    allow from all

# disable directory browsing
    Options All -Indexes

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</ifmodule>
user2197774
  • 453
  • 1
  • 6
  • 20

1 Answers1

1

WordPress will update htaccess file when you change the permalink structure, usually it does between the tags of BEGIN and END WordPress.

EIDT: Since its pointed out in the comment that htaccess has been modified inside BEGIN and END tags which would allow your custom rules to be overriden if permalinks are changed or any updates are performed which contain changes to htaccess.

Some Plugin might change it and they also try to do it within their own tags.

Anything you have added as custom rules or code outside of BEGIN and END tags will be perserved in htaccess.

As for the upload directories,I think that is also configurable whether multisite is based on sub-domains or sub-directories structure.

Mehmood
  • 66
  • 1
  • 5
  • "Anything you have added as custom rules ... will be perserved in htaccess." - Except that the OP had manually edited code in the `# BEGIN WordPress` / `# END WordPress` code block (relating specifically to file uploads) - this will **not** be preserved when WP is updated (or permalinks are changed), which would seem to be what caused the OP's problem. – MrWhite May 20 '22 at 17:32
  • Yep, that makes sense. Sorry I missed that. – Mehmood May 20 '22 at 18:19
  • I see thank you. Could anyone explain what these two lines will do. The ones added between the Wordpress begin and end in htaccess ? # 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] – user2197774 May 20 '22 at 18:23
  • Here is a link to htaccess explanation from wordpress. https://wordpress.org/support/article/htaccess/ – Mehmood May 20 '22 at 18:30
  • I think you are using an older version of htaccess, I am thinking it was used in wordpress 3.4 and before. – Mehmood May 20 '22 at 18:31
  • According to bit of research, it looks like that uploaded files code is related to multisite sub-folder installation type. Secondly, your multi sites uploaded images/files should in '/wp-content/uploads/sites/' folder or /wp-content/uploads/blogs.dir/ folder. Each subsite should have a folder according to their ID. So the main site has an ID of 1, and uploads images in wp-content/upload. But your sub-site should have an id of 2 and should upload images in either '/wp-content/uploads/sites/02' or '/wp-content/uploads/blog.dir/02'. – Mehmood May 20 '22 at 19:20
  • @user2197774 The second one is self-explanatory, as per the comment, it appends a trailing slash to requests for the (possibly "virtual") `wp-admin` folder (this is standard WP). However, the first rule internally rewrites any request for `//files/` (where `/` is optional) to the script `/wp-includes/ms-files.php?file=`. That first rule is not standard WordPress. – MrWhite May 20 '22 at 22:29
  • Thanks, I am still not quite understanding that one line. I have a file https://content.scienceofecd.com/play/files/2020/02/NCF-postcard-300x150.png that I cannot find in the uploads folder or anywhere else on the server. I am sure it is connected to the rewriting of the uploads. Any thoughts ? – user2197774 May 20 '22 at 22:43
  • @user2197774 That request would be internally rewritten to `/wp-includes/ms-files.php?file=2020/02/NCF-postcard-300x150.png` - for the `ms-files.php` script to handle the request and serve a response. This is a common technique for when images are dynamically resized or are behind some kind of authentication or need some additional processing before being sent to the client. The file may exist as a different filename, or not exist at all if the image is generated by the script itself. – MrWhite May 20 '22 at 23:32