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.
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/###
toexample.com/###
. There are several redirection plug-ins available, but this one has a very refined UI and is very easy to use.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.
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.
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.