Update WordPress URL when changing links, new domains

Many of you have asked me about updating the domain name transfer or changing the link of a Website using WordPress. It greatly affects SEO if you do not do this properly and timely. In this article, I will guide you through the cases you are facing if you do not want to affect the results of SEO by immediately updating the URLs when changing the link or moving to a new domain name. You will need in the following cases:

  • Switch from HTTP to HTTPS
  • Change from domain A to domain B
  • Change the example link from www.domain.com/link-old to www.domain.com/link-new
  • Change whole page data from content A luxurious content REMOVED

In this article, I will guide you by running the command on phpmyadmin and from the VPS console. If you want to use Plugins to do this, then refer to this article: Switch from HTTP to HTTPS without worrying about losing SEO.

Update WordPress URL when changing domain name, new URL

After migrating a WordPress site to a new URL or to a live site (this is common when you initially do it on localhost and then move to your own domain), the new URL string in the mysql database need to be changed and updated in different mysql database tables.

Update WordPress Database

Before doing this, I recommend that you back up a copy of your data just in case you don’t feel confident you’ll do it correctly or if something goes wrong.

Go to the SQL of the database size you want to update, run some update sql and replace commands on the tables, wp_options, wp_posts, wp_postmeta. These are also the tables that contain the content, the url to replace.

Read more:  How to have an effective search description?

Use the code like below and swap in your old and new URLs, without the underscores. In addition, if necessary, change the table prefix values ​​if applicable (ie wp_ is the default of WordPress when installing, but many of you change it to different, please pay attention to change it in the command below)

UPDATE wp_options SET option_value = replace(option_value, "http://www.URLcũ', 'http://www.URLmới') WHERE option_name="home" OR option_name="siteurl";
UPDATE wp_posts SET guid = replace(guid, 'http://www.URLcũ','http://www.URLmới');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.URLcũ', 'http://www.URLmới');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.URLcũ','http://www.URLmới');

Phpmyadmin runs SQL command to replace data

Or you can use the command through terminal

[email protected][~/Desktop]: mysql -u username -p databasename
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 892
Server version: 5.5.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> UPDATE wp_options SET option_value = replace(option_value, 'http://www.URLcũ', 'http://www.URLmới') WHERE option_name="home" OR option_name="siteurl";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0

mysql> UPDATE wp_posts SET guid = replace(guid, 'http://www.URLcũ','http://www.URLmới');
Query OK, 0 rows affected (0.02 sec)
Rows matched: 964 Changed: 0 Warnings: 0

mysql> UPDATE wp_posts SET post_content = replace(post_content, 'http://www.URLcũ', 'http://www.URLmới');
Query OK, 0 rows affected (0.05 sec)
Rows matched: 964 Changed: 0 Warnings: 0

mysql> UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.URLcũ','http://www.URLmới');
Query OK, 0 rows affected (0.01 sec)
Rows matched: 686 Changed: 0 Warnings: 0

So, after using one of these two ways, you have updated all new links in your website data. For many cases it is very necessary to replace the content data. For example, those who SEO products are 2017, but when 2017 is over with those products they need to change 2017 to 2018 then it is completely easy to do it all at once with how 1 runs the SQL command.

Read more:  What is link building? The importance of links in SEO

I often have to do this when I install SSL from HTTP to HTTPS for some of my readers who have questions and want guidance. There are many benefits of doing this, especially in SEO if you need to convert 1 link A of all internal links into link B then just do the command once, you can be sure that I have reset internal link to link B on my entire Website.

This is just a fairly short technical guide, so I’ll leave the issues related to it in a recent post. Hopefully, you will have useful insights for your Website.

Compilation: Phong Vu

Source link: Update WordPress URL when changing links, new domains
– Witgie.com

Leave a Reply

Your email address will not be published. Required fields are marked *