How to change domain name in wordpress
Due to various reasons, we sometimes need to change the domain name of WordPress, and the domain name of WordPress is written directly into the database. It is obviously not possible to directly change the domain name bound to the WordPress site in the server. In addition to this work, we You also need to replace the old domain name in the WordPress database with the new domain name to completely complete the WordPress domain name replacement.
#In this article, I will introduce you to several ways to change your WordPress domain name. I need to remind everyone in advance that before modifying the WordPress database, you must make a backup just in case.
Use the wp-cli tool to search and replace the domain name to change the WordPress domain name
wp-cli is a command line tool that allows us to install and update WordPress through the command line , which is quite convenient to use to perform some batch operations on WordPress.
Install the wp-cli tool
If you have already installed the wp-cli tool, proceed directly to the next step.
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
Search and replace domain names in the WordPress database
The wp-cli tool provides us with a command to search and replace characters in the database. Execute the following command directly in the root directory of WordPress to complete the replacement. To operate the WordPress domain name, this command supports some options to facilitate our customized operations. For details, please see the official instructions of the wp search-replace command.
wp search-replace 'old.com' 'new.com'
Use SQL statements to directly replace the domain name in the database
Run the following command directly in phpMyAdmin to replace the old domain name with the new domain name. After copying the code, replace old.com, new.com, if your WordPress site uses a custom data table prefix, and modify the ‘wp_’ data table prefix in the following command.
UPDATE wp_options SET option_value = replace(option_value, 'http://old.com', 'http://new.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://old.com','http://www.newurl'); UPDATE wp_posts SET post_content = replace(post_content, 'http://old.com', 'http://new.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old.com','http://new.com'); UPDATE wp_usermeta SET meta_value = replace(meta_value, 'http://old.com', 'http://new.com'); UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'http://old.com', 'http://new.com'); UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'http://old.com','http://new.com');
In most cases, the domain names written into WordPress exist in the above data tables, but it does not rule out that custom data tables added by themes or plug-ins also contain old domain names. If the above is executed After the command, there are still some old domain names that have not been replaced. You can refer to the method below to directly edit the .sql file to replace them.
Use a code editor to edit the .sql exported file and directly replace
Export the .sql file, then use your favorite code editor to open the exported .sql file and search Replace the old domain name with the new domain name.
Then directly delete all data tables in the site database and then import them into the database.
Set 301 jump to import the traffic of the old domain name into the new domain name
If your site has been included by the search engine, you can make a 301 jump in Nginx Set up and import the traffic of the old domain name to the new domain name.
server { listen 80; server_name old.com new.com; return 301 http://new.com$request_uri; }
Finally, I would like to remind you again that you must make a backup before modifying the WordPress database. If something goes wrong during the modification process, we can easily restore the data without causing too much loss.
For more WordPress technical articles, please visit the WordPress Tutorial column!
The above is the detailed content of How to change domain name in wordpress. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

WordPress templates quickly create professional websites. The steps to import a template include: select and download the template. Log in to the WordPress dashboard. Select Theme from the Appearance menu. Click "Add New Theme". Click "Upload topic" and select the downloaded template .zip file. Click "Install Now". Click the "Activate" button. Customize the templates through the Customize menu.

To log in to a WordPress website account: Visit the login page: Enter the website URL plus "/wp-login.php". Enter your username and password. Click "Login". Verification Two-step Verification (optional). After successfully logging in, you will see the website dashboard.
