Fixing broken media URLs after moving to WordPress Multisite

I recently moved all my blogs into a single WordPress Multisite installation. However, I know have the problem that media links are broken – not only in some of my blog posts, but also across the internet whereever I embedded images from my media library.

This is the regular URL
http://mydomain.com/wp-content/uploads/2013/12/filename.gif

Read More

This is the URL after installing MU:
http://mydomain.com/wp-content/uploads/sites/2/2013/12/filename.gif
where the following are variable:
http://mydomain.com/wp-content/uploads/sites/[siteID]/[year]/[month]/[filename].[ext]

Is it possible to fix this problem with htaccess URL forwarding and regular expressions? How exactly would the htaccess command and the regular expression look like? (Unfortunately I’m somewhat illeterate when it comes to regex)…

Related posts

Leave a Reply

1 comment

  1. This should work for you.:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/wp-content/uploads/sites/2/
    RewriteRule ^wp-content/uploads/(.*) /wp-content/uploads/sites/2/$1? [R,L]
    

    If the url doesn’t contain wp-content/uploads/sites/2/ then it will add the sites/2/ to the url