Home › Forums › WordPress › How to replace old website urls with new website in database?
Tagged: wordpress website
This topic contains 2 replies, has 2 voices, and was last updated by James 4 years, 2 months ago.
I migrated my site from old server to new server. I have more than 300 posts and 100+ pages in my website. I want to replace my old website’s Urls with new Website URL.
Please give suggestions.
Make sure you have the new database selected, then run some sql updates and replacement commands on the tables notably, wp_options, wp_posts, wp_postmeta.
Use the code as below and swap in your old and new URLs, no trailing slashes. Also if necessary change the table prefix values where applicable (ie wp_ )
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
Thanks For the reply. The code provided by you is working perfectly Fine.
Mail (will not be published) (required):
Enter the destination URL
Or link to existing content