Keep wp-content/uploads urls for SEO

I’ve migrated and redesigned a page from normal wp folder structure to bedrock. The page has lots of traffic already and is ranking with lots of images on google.

Problem is that now all image paths have changed from to - which the client doesn’t want in terms of seo.

what would be the best fix for this?

I tried:

  • using symlinks to redirect app/uploads to wp-content/uploads --> this worked so far, but will result in different image paths for new and old media files, which might bring us in to even bigger trouble in future
  • redirecting via redirection-plugin (not good for performance and google might not like this)

other idea:
changing paths in bedrock, so that media-files will live in wp-content/uploads. what are pros cons here and if possible how would I accomplish this?

Are there better solutions for this? Probably I’m not the first one with this problem, but couldn’t find suitable answer on the forum yet …

1 Like

You could directly change the nginx config template for that site and add a redirection on nginx-level.
IMHO Google doesn’t care whether the redirection headers were emitted by a redirection plugin or by nginx, in the end the right HTTP redirection code matters.

1 Like

To keep the image rankings but use the /app/uploads/ after migration, I use this NGINX location block:

location /wp-content/ {
    rewrite ^/wp-content/(.*)$ /app/$1 permanent;

You can test any of the /wp-content/ links, they should all perfectly redirect to the new location.


Thanks for this peace of code, I think I will do this rather than using the redirection plugin. but where do I place this code? On apache I would place it in .htaccess, and on nginx?

in order to keep a page wp-path-consistent (who knows if the client wants to move back to a normal wp-install one day), is there any possible solution of telling bedrock to put the uploads-folder where it originally belongs (in wp-content)? or will this be a problem when updating wordpress?

When I did rerouted web/wp/wp-content to web/app via symlinks (and search-replaced image-paths back to wp-content/uploads in db), it worked for the original image files, but th srcset-files still had the bedrock-paths.

I didn’t understand why … are the srcset-paths dynamicaly generated instead of being called from the db? and anyway how does wordpress suddenly know (after migration), that the image-path has changed? I didn’t do any search-replace for this. is there already a nginx-rewrite-rule implemented in bedrock or so?

The snippet I sent goes in your nginx conf file… are you using nginx or apache? I shoulda asked that at first, probably…

Hey yes I’m using nginx.

I read this on how to edit nginx conf in trellis:

Just to make sure (I’m new to nginx configs):

I add a file like i.e. trellis/nginx-includes/rewrites.conf.j2 and in this file I place:

location /wp-content/ {
    rewrite ^/wp-content/(.*)$ /app/$1 permanent;

and thats it? this will work on dev, staging and prod after reprovisioning?

do I have to restart nginx to make it work?

by the way: what does the $1 mean?

I wish I were better with nginx as well. If you’re using Trellis, I’m pretty sure you can set that up to make sure all environments are the same… I’m not a trellis guy, though… yet. So I, unfortunately, cannot confirm the config as you have stated.

On my digital ocean server I typically edit the config file for the specific site I’m working on, and just add that location block near the rest of the location blocks… :man_shrugging:t3:

As far as I know, you would need to restart nginx with any conf changes.

The $1 is the variable that comes from the first (.*)$. It represents everything after /wp-content/ from the incoming string.

That can be put simply in trellis/nginx-includes/all/redirects.conf.j2.

Run e.g.: ansible-playbook server.yml -e env=production --tags nginx-includes


Hello. How do I do the same trick on apache?
For SEO I need the links to be wp-content / uploads, not app / uploads.
Thousands of photos have already been indexed.
I really look forward to your answer, thanks!

This topic was automatically closed after 42 days. New replies are no longer allowed.