Search code examples
phpdatabasewordpressdatabase-migrationbroken-links

Is there any easy method to update media or page links inside a wordpress post or page after website migration


I have a wordpress website, that i just completed customisation within my localhost. Where i set permlinks http://localhost/nwp as my siteurl and home url. And in my website i used links inside my pages and posts for referring images,videos and other pages and posts. When i migrate this website into my live server i changed my site url and home url to http://mydomain.com. but the url i pasted inside pages and posts still exists as old like http://localhost/nwp/uploads/2014/img.jpg ,http://localhost/nwp/your-page etc.. I can fix this issue by opening all pages or posts and replacing those old links inside pages or posts with new links .But it take too much time. i didn't know any other method to solve this problem easily.Please help me If any one know a better method to fix this issue easily


Solution

  • Thank you all for your Answers. But I just found a secure and easy way without any help of additional download script. we need to execute sql UPDATE query to update all contents in database as below.

    mysql> UPDATE wp_posts SET guid = replace(guid, 'http://localhost/nwp','http://mydomain.com');
    
    mysql> UPDATE wp_posts SET post_content = replace(post_content, 'http://localhost/nwp', 'http://mydomain.com');
    
    mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://localhost/nwp','http://mydomain.com');