Wumple.com

2024/05/09

WordPress missing images after host migration?

Filed under: — Stormwind @ 7:05 am

When migrating some WordPress blogs on a multisite install to a new host running Ubuntu, I found all the images were broken in every blog except the first one.

Eventually I found the culprit: the /usr/share/wordpress/.htaccess file was being ignored, which meant the Apache httpd RewriteRule of requests for files/ was not being redirected to the correct blogs.dir/… files (and let’s not dwell on how inefficient it is serving large files via ms-files.php, which is apparently only used for multisite blogs created before WordPress 3.5):

RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

To fix this problem, I enabled .htaccess for /usr/share/wordpress by creating /etc/apache2/conf-available/wordpress.conf with the following contents:

# Allow .htaccess in WordPress directory
# Without this to enable .htaccess, images/files in multisite WordPress installs would be broken due to missing rewrite rule

<Directory /usr/share/wordpress>
        Options Indexes FollowSymLinks
        AllowOverride All
</Directory>

Then I enabled it with a2enconf wordpress.conf and systemctl reload apache2.

Hope this helps someone save some time!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

|| RSS 2.0 || Comments RSS 2.0 || XHTML || Powered by WordPress ||