Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I migrated my WP deployment from the old server to the new server. The site still has the same URL (i.e. http://my.site.com) but I've moved my WP deploy from the site URL to a subdirectory of said URL (i.e. the WP deploy used to be found at http://my.site.com, but now it's at http://my.site.com/blog).

The good news is that I've got all the textual content migrated. The bad news is that the images aren't loading correctly. I took a closer look at the URLs for images embedded in posts and they all look something like this:

<img style="padding: 7px;" src="/wp-content/uploads/image.jpg" alt="Image" width="172" height="154" align="right" border="0">

Note the forward slash in the src attribute. What's happening is that the browser is looking to load the image at http://my.site.com/wp-content/uploads/image.jpg. But the site is deployed at http://my.site.com/blog now. I can find the image if I cut and paste the URL into my browser and pre-prend the correct WP site URL (i.e.http://my.site.com/blog/wp-content/uploads/image.jpg).

What kind of WP kung-fu do I need to correct this?

I have read:

http://codex.wordpress.org/Moving_WordPress

I have looked at these:

http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ http://wordpress.org/extend/plugins/velvet-blues-update-urls/

And they don't exactly help.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

It's a bit odd that there are root-relative URLs, WordPress by default uses absolute URLs when inserting images. However, probably the quickest fix is to open the SQL file in a text editor and just search and replace src="/wp-content/ with src="/blog/wp-content/, or the absolute URL, whatever you prefer.

share|improve this answer
    
Can you point me to the documentation in the Codex on this? This is a good suggestion, though. –  Avery Chan Mar 24 '13 at 6:06
    
I used this suggestion. Just for anyone that's looking at this as a solution. Use sed (I tried to use a text editor but my file was too large): sed -E 's/<img([^>]+src=\\\")(\/wp-content[^>]+>)/<img\1https:\/\/my.site.com\/blog\2/g' < blog.mysql > blog.mysql.new This is with whatever sed comes with Mac OS X 10.7.5 –  Avery Chan Mar 25 '13 at 4:42
add comment

Forward slash is a good thing to make sure that you are accessing the resource from a path relative to the root domain

Why not just create a rewrite rule in the .htaccess like the one below and then always access it "/assets/img/". Makes more portable always

RewriteEngine On
RewriteBase /
RewriteRule ^assets/img/(.*) /wp-content/uploads/$1 [QSA,L]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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