Chris
Chris

Reputation: 63

WordPress Move to WordPress Network

I have a very interesting issue. I migrated a website from a normal WordPress installation to a WordPress Network. The main issue I'm having is folder structure.

The specific issue is with images. So here is an example:

Old Image Path: /wp-content/uploads/image.jpg or /wp-content/uploads/year/month/image.jpg

With the network, the above paths were changed:

New Image Path:

/wp-content/uploads/sites/SITE-ID/image.jpg or /wp-content/uploads/sites/SITE-ID/year/month/image.jpg

The problem I'm having is that Google indexed all the images according to their old URLs. We get a lot of leads from Google images because people search in images for our products and then end up at our website.

I have tried a rewrite rule like this one to fix it:

rewrite ^/wp-content/uploads/(.*).(png|jpg|gif) /wp-content/uploads/sites/4/$1.$2 ;

However, the issue with the above is that it's now rewriting working images as well:

https://www.my-webiste-url/wp-content/uploads/sites/4/2018/08/image-300x300.jpg is being rewritten to https://www.mysite-url/wp-content/uploads/sites/4/image-300x300.jpg (the problem is because of the year and month that is also included in the URL.

Does anyone have some advice?

Upvotes: 2

Views: 69

Answers (2)

Jigar
Jigar

Reputation: 1

You could also try from Settings > Permalinks in WordPress admin.

Upvotes: 0

Richard Smith
Richard Smith

Reputation: 49702

You could try a negative lookahead assertion in the regular expression to discard matches that include the /sites/ literal.

For example:

rewrite ^/wp-content/uploads/(?!sites/)(.*\.(png|jpg|gif))$ /wp-content/uploads/sites/4/$1;

Upvotes: 1

Related Questions