1

I've moved my installation from example.com/beta to example.com and I've noticed that there are a few broken images. Looking at the source, it appears that they are still looking in looking in the /beta directory for the images.. How can I fix this?

The pics which are broken seem to be the ones uploaded from within the page/post editor.

(Note:I exported the database to a file and there were many instances of example.com/beta in it .. I wonder if I can find-replace to get rid of the beta and then import the db..?)

EDIT

In the end, I went into each post, and edited each broken image (Edit Image > Advanced Settings) to take out the beta/ before wp-content. I was too scared to edit the exported sql and re-import it. If it happens in the future I would just re-create the /beta/wp-contents/uploads with the contents of /wp-contents/uploads until I found the patience to go thru and change each image paths.

5
  • Images in post content? More details please on how were they added (media attachment, FTP upload, etc).
    – Rarst
    Sep 13, 2010 at 16:56
  • yes, images added within pages/posts. not images used in css etc.
    – cannyboy
    Sep 13, 2010 at 17:01
  • Using image attachment? Sorry for bugging for details, but there are maaaany ways to abuse images in WP. :)
    – Rarst
    Sep 13, 2010 at 17:10
  • Using the Upload/Insert > Add an image > 'Select files' button, when you are editing a post/page.. The images were inserted into the page when the site was in /beta
    – cannyboy
    Sep 13, 2010 at 17:24
  • You might want to place your solution in a separate answer and mark it as accepted. That way, the system knows this question is answered.
    – Jan Fabry
    Oct 19, 2010 at 15:17

4 Answers 4

2

When images are added to WordPress posts and pages, they are stored with the absolute url to the image file on the server. If you change your WordPress installation (move to a different domain, change your folder structure, etc) then you'll break these images. There are two ways to fix this:

Manually re-write URLs

The most time-consuming path is to sit down and do a find/replace on all image URLs in your site. If you have a large site, this can take forever to do by hand and you'd be well-served writing a script to do it for you. Do a search on the WP support forums and you'll find a host of pre-written scripts to do just that, but most require a higher level of technical skill or access to your site than most people have.

Use a rewriting plug-in

I've moved my blog a few times. It started out as http://eamann.com/wordpress/. Then it moved to http://eamann.com/mindshare/. Then it was http://mindshare.eamann.com. Then it moved to its current home at http://mindsharestrategy.com. Each time, I had the same problem you're facing now - my images broke.

Rather than manually re-writing my image URLs each time, I installed a redirection plug-in to do it for me. After the first move, if you requested http://eamann.com/wordpress/image1.jpg the server would instead give you http://eamann.com/mindshare/image1.jpg.

You could use a similar redirection script to point all requests to example.com/beta/### to example.com/###. There are several redirection plug-ins available, but this one has a very refined UI and is very easy to use.

2
  • The rewriting seems very hack-ish, and the plug-in linked to seems to be broken for WP 3. I exported the database to a file and there were many instances of example.com/beta in it .. I wonder if I can find-replace to get rid of the beta and then upload?
    – cannyboy
    Sep 13, 2010 at 17:52
  • 1
    Find-replace works just fine (remember, that was the first suggestion) and it's what I had to do when I moved my site to a new domain on a different server. Rewriting only works if you're still on the same system ... and as you can see from the 10/33 split on the compatibility widget, it works on some instances of WP3 ... but obviously not all. It works on my site (WP 3.0.1) or I wouldn't recommend it.
    – EAMann
    Sep 13, 2010 at 18:43
1

You need to manually update your database to fix images path on posts / pages. I believe there's plugin that do this. I'll update this answer later when I found one.

1

Just for future reference, this post on SQL queries could be helpful to some folks. There is also a commercial product from iThemes that might be useful, especially if you're going to do this kind of move regularly.

1

If it is down to it - plugin for search and replace in WP with serialized support

Just be sure to backup and everything. I'd first test on local copy of database if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.