InMotion Hosting Support Center

As we continue our tutorial series on migrating your WordPress site to Inmotion Hosting, the next thing we want to cover is how to update the URLS for images within your pages and posts. They are coded differently so simply changing the site URL will not fix this. In this tutorial we show you how to fix this by using your phpMyAdmin tool.

IMPORTANT! Note that this step is not mandatory. It is only necessary if your domain name is changing during the migration.

Correcting image links after a migration

  1. Log into your cPanel interface.
  2. select phpmyadmin toolOnce inside the cPanel, find the Databases category and click on the phpMyAdmin tool icon.
  3. select new databaseYou are now on the main phpMyAdmin page. Find the newly added database and click on its name from the left-hand sidebar. Our sample database is named testdb.
  4. select database tableThis opens the database and the screen refreshes with a list of the tables. Using the sidebar again, find and click on the wp-posts table.
  5. click the SQL buttonLook to the top of the screen and you will see several tabs that run across the page. Click on the SQL tab.
  6. enter the SQL code and run it

    You are now on a MySQL editor screen. In the code area, copy the following bit of MySQL.

    UPDATE wp_posts SET post_content=(REPLACE (post_content, '<old url>','<new url>'));

    Be sure to replace <old_url> with the old sitename and <new_url> with the new site name. For instance, our original site was inmotiontesting.com and the new test site will be at test.inmotiontesting.com so the code should appear as below:

    UPDATE wp_posts SET post_content=(REPLACE (post_content, 'inmotiontesting.com','test.inmotiontesting.com'));

    Click on the Go button to run the code and change the URLs for all images in the posts. This will also affect any other 'hard coded' links that were in the posts that pointed to the original site.

    Below are before and after shots of the changes made. Note that the image paths are displayed in the lower left hand corners of the images. You can see how they switched to the new sitename after the SQL code ran.

    BeforeAfter
    before the link changeafter the link change
You are viewing Section 5: Correcting image links after a WordPress migration
Section 4: Configuring WordPress After a Migration
Section 6: Testing your WordPress website after Migration

Support Center Login

Social Media Login

   
Social Login Joomla

Related Questions

Here are a few questions related to this article that our customers have asked:
How do I fix image links after domain change?
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-09-13 3:04 pm

I followed the instructions concerning image links after migration,  however the images are still not being loaded when viewed in browsers. Can you offer any other instructions to assist?

Staff
39,221 Points
2014-09-15 8:19 am
Hello Rexford,

Right click on one of the missing images and get the image information from the menu there. This will include the URL where the program is looking for the image. Check to see that it is correct. If not, then run through the above again to change the URL. If it is still occurring we may need to take a look at files your account if you are one of our customers to see where the settings are incorrect.

Kindest Regards,
Scott M
n/a Points
2014-10-11 3:59 pm

After hours of hours searching I can finally proceed.sign...that feeling. thanks alot Sir! 

n/a Points
2014-10-12 10:13 am

Thanks for the tip but that only changes the image link and not the URL the image is linked to which can be either an attachment, image or custom URL.

Staff
39,221 Points
2014-10-12 4:39 pm
Hello Sam,

As a general replace query, it will replace all URLs of the set type to the new one, but specifically in the post_content column on the wp_poststable. If you need to replace URLs in other columns or tables, you would use the same type of query, but for that particular table/column combination.

Kindest Regards,
Scott M
n/a Points
2016-01-13 8:23 pm

Is there a way to apply this across all tables efficiently?

Staff
34,213 Points
2016-01-14 3:04 am
Hello Nic,

You would need to specify ALL of the tables that you would be updating in the query. Look at the bottom answer in this post about updating multiple tables in a query. I hope that helps to answer your question! If you require further assistance, please let us know!

Regards,
Arnel C.
n/a Points
2016-07-08 3:59 am

Hi Sir...

Can solve my problem..?

My images url Start with http://**.com/*******.com...

why not show my domain name url http://www.********.com /------ .Jpg

Staff
24,701 Points
2016-07-08 11:51 am
Are you using a CDN service or plugin in WordPress?

Thank you,
John-Paul
n/a Points
2014-11-02 7:59 am

Hi, thank you for your article. thats really helpfull for me. I just updated mine 1000+ images links. Wishing you very best of luck for your business.

n/a Points
2014-12-18 3:52 am

Good day, i tried it but i keep getting this      #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE wp_posts SET post_content=(REPLACE (post_content, 'localhost:81/impgaller' at line 2  

    the images are linked to my local host because i built it locally now its online and i cant change the links. Help

Staff
39,221 Points
2014-12-18 8:58 am
Hello Steevy,

Thanks for contacting us about your error. Does the error message give the complete query? The replace statement appears to be incomplete and would give that type of error if run in that fashion. Be sure it has a second parameter with the new location for the images and closes out with double parentheses, like )).

Kindest Regards,
Scott M
n/a Points
2015-01-23 11:00 am
Perfect... being careful and following step by step as shown will work!
n/a Points
2015-03-31 9:21 pm

you are the man, thanks

after a migration i still have some errors but this one is solved

n/a Points
2015-04-02 7:29 am

thanks a lot! u saved my life

n/a Points
2015-04-04 2:11 am

Will it work if my old site is from a localhost, localhost:8888/wordpress? Tried it but it is not working.

Staff
24,701 Points
2015-04-06 1:09 pm
Hello Elliot,

Thank you for your question. Yes, it should still work. Essentially, it is just performing a find & replace in your database.

Thank you,
John-Paul
n/a Points
2015-06-05 8:13 am

thanks.. it solved my problem.. any way, is it ok to export the database.sql then find and replace the old url with the new one, then import it again ?

i have tried once.. but it shows error like this :

ErrorSQL query: ---- Dumping data for table `wp_comments`--INSERT INTO `wp_comments` (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`, `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, `user_id`) VALUES(1, 1, 'Mr WordPress', '', 'https://wordpress.org/', '', '2014-09-16 17:32:31', '2014-09-16 17:32:31', 'Hi, this is a comment.\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.', 0, 'post-trashed', '', '', 0, 0);MySQL said: Documentation  #1062 - Duplicate entry '1' for key 'PRIMARY'

 

Thanks again..

Staff
39,221 Points
2015-06-05 10:12 am
Hello Pinpin,

Yes, you can export and then make changes to the file and import it again. That is certainly another option.

Kindest Regards,
Scott M
n/a Points
2015-06-09 3:48 pm

Hi, I am trying to migrate from a WP site on my local computer to my temp url at inmotionhosting. I tried plugging in what i thought was the old url (localhost/wp) and the new temp url into the code, but nothing seems to happen. (Message is a green checkmark but says "0 rows affected.") I am also having problems with one of the permalinks in my main menu. What am I doing wrong?

Staff
10,077 Points
2015-06-09 6:37 pm
Hello Mary,

You can use this guide to force wordpress to use your temporary url. As for your menu please try resetting your permalinks within the admin dashboard.

Best Regards,
TJ Edens
n/a Points
2015-07-04 6:30 am

Hi thereI am unable to find wp_posts in my database. Please help.

Staff
39,221 Points
2015-07-06 3:54 pm
You can view the database tables via the phpmyadmin tool. Click on the database name and you will see them in a list. The table has to exist or your site will not work so it is there.
n/a Points
2015-07-04 6:53 am

Site is alternating between the live version and the test version. Not sure what went wrong. Can anyone help pls?

Staff
39,221 Points
2015-07-06 3:55 pm
Do the posts alternate URLs or the images?
n/a Points
2015-08-11 1:41 pm

Though i know basics of database/sql but still i was pretty scared after adding this sql query. but to my surprise it's working fine. thank you very much

n/a Points
2015-08-27 10:43 am

So just to clarify...if I do this procedure for other tables it would look like this? TIA.

UPDATE wp_<some_table> SET post_content=(REPLACE (post_content, '<old url>','<new url>'));
Staff
24,701 Points
2015-08-27 4:20 pm
Hello Amy,

Thank you for contacting us. Yes, your query looks correct.

If yo have any further questions, feel free to post them below.

Thank you,
John-Paul
n/a Points
2015-09-30 10:31 am

after going through your tutorial, i was pleased with the way your detailed  and how easy you made it looks, but unfortunately it did not work for me as i keeping getting the bellow errors

Error

SQL query:

 

UPDATE wp_post SET post_content=(REPLACE_content,'predictiontips.com/wordpress','predictiontips.com'))

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

Staff
34,213 Points
2015-10-01 8:35 am
Hello Mike,

Sorry for the problems with the replacement code. Your error indicates that you have a syntax issue in the code you typed. SQL is unfortunately not forgiving in its need for punctuation and proper spacing. Check out the original code:

UPDATE wp_posts SET post_content=(REPLACE (post_content, '',''));

Then here is your code:

UPDATE wp_post SET post_content (REPLACE_content,'predictiontips.com/wordpress','predictiontips.com'))

You're missing the 'post_content' and the also the parentheses are not correct. Copy the original code syntax and the query should work with no errors.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2015-12-29 6:15 pm

Hi, I am trying to move my wordpress website from one domain to another and I did the changed to the options table and to the posts table (sql query). It went OK, got message so many rows affected, However, the images still point to the oldsite.com. Is there anything else I can do? Thank you.

Staff
4,899 Points
2015-12-29 9:54 pm
Hello Katie,

I regret to hear that the above steps didn't work for you. Have you tried editing the database manually to see if the changes take effect?
n/a Points
2016-01-18 10:11 am

HI, it's all sorted. It wouldn't work, so I had to redo the website a bit (used XML site, imported to a fresh new Wordpress and made some changes) after that everything works. So happy I backed up the site pfff... 

2016-01-26 9:44 am
This is similar to a question above, but I just want to clarify - I am transferring a WordPress site from my own computer, where the url displays as localhost/wordpress/ - I would use this as the old url?
Staff
4,899 Points
2016-01-26 7:23 pm
Yes, you would just make sure you change all instances of localhost/ in your database with the new domain. If done correctly the site will function as expected.
n/a Points
2016-02-26 4:16 am

Hello I just followed your this procedure but " 0 rows affected. (Query took 0.0781 sec)". What esle should I try here to fix my issue. 

 

(My hosting is with godaddy just to let you know. My old domain which was redirected to my new domain expired recently and this images url issues occurs from that time. 

Staff
10,077 Points
2016-02-26 11:50 am
Hello Alok,

When you ran the command did you specify your correct prefix as even though wp_ is the default it may not be correct for you.

Best Regards,
TJ Edens
n/a Points
2016-04-05 1:34 am

My old site address is the same as my new one. I did this now images I add to the site are broken. How do I fix this?

Staff
11,403 Points
2016-04-05 7:55 am
Ideally, if the site URL is the same, then the URLs for the images would remain the same as well. Check to make sure the images are on the server. Also, do you have a URL example to the new site so we can take a look for you?
n/a Points
2016-04-22 6:53 am

Hi I just followed your steps and have managed to create a test site successfully, however the images on my products pull through to the main site. I am using a plug in to house the images, what syntax should I be using if I have a third party plug in housing my product images?

This is my error message: #1054 - Unknown column 'post_content' in 'field list'

Thanks in advance

Staff
10,077 Points
2016-04-22 10:24 am
Hello Justin,

Pretty much the error is stating there is no column called post_content in the table you are pulling data from. Please check your table to make sure it is there and you may need to repair your database which can be done via the cPanel.

Best Regards,
TJ Edens
n/a Points
2016-04-25 10:06 am

Hi TJ

 

Thanks for the feedback, you're correct,I have checked the table and I see now that when I open phpMyAdmin and navigate to the SQL tab is already populates with the following command: 

SELECT * FROM `wpwp_huge_itportfolio_images` WHERE 1

My images are held in that portfolio on the main site, what would I need to do to re-direct them to the test site?

 

Thanks again

Staff
39,221 Points
2016-04-25 2:24 pm
You would use the same script above as a template, but switch the table name and column name to reflect what the plugin uses.
n/a Points
2016-05-04 7:50 am

Thanks very much, worked like a charm 

n/a Points
2016-05-11 8:25 am

Hey I saw your article and I follwed the same. I have used that SQL query too. The problem with my site is it is showing all the images except logo. The image source for logo file is still pointing to localhost than my current live site. My site address is - agarwal.net16.net. 

Below are few lines which I saw on page source of my website-

<div id="site-logo">   <a href="http://agarwal.net16.net/" rel="home">   <img src="http://localhost/wordpress1/wp-content/uploads/2016/05/net4g.jpg" alt="NET4G">   </a>  

</div>

 

Staff
34,213 Points
2016-05-11 2:20 pm
Hello Sneha,

Sorry for the problem with the graphic. I would suggest that you get the original graphic file for the logo and re-upload it into the media library for your installation. The link is definitely wrong - you will need to correct it or remove and re-add it in order to make sure that the logo is correctly referenced. It definitely can't have the current path you're using as it doesn't work on the internet.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2016-05-24 12:50 am

Do you have any idea why I'd be getting this error?

Error

SQL query:

 

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.thefreebieaddiction.com', 'http://www.momlifeinpnw.com')

MySQL said: Documentation

#1146 - Table 'thefrem7_wordpress651.wp_posts' doesn't exist

 

Staff
4,899 Points
2016-05-24 8:59 am
It looks like MySQL is having trouble finding the table for the WordPress posts. It is possible the table was deleted, or the WordPress tables were not imported into the database.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

50 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!