search
HomeCMS TutorialWordPressHow 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.

How to change domain name in wordpress

#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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How easy is it to manage content with WordPress?How easy is it to manage content with WordPress?May 09, 2025 am 12:11 AM

WordPressisuser-friendlyduetoitsintuitiveinterfaceandCMS,whichseparatescontentfromdesign.Itoffersarichtexteditorforeasycontentcreationandamedialibraryfororganization.Itsflexibilityisenhancedbynumerousthemesandplugins,thoughoverusecanimpactperformance

How is WordPress used in business settings?How is WordPress used in business settings?May 08, 2025 am 12:04 AM

WordPressissuitableforbusinesssettings.1)Itsupportse-commercewithpluginslikeWooCommerce,allowingproductmanagementandpaymentprocessing.2)ItservesasaCMSforcorporateblogs,enhancingSEOandengagement.3)Customizationispossiblewithnumerousthemesandplugins.4)

What types of websites are not a good fit for WordPress?What types of websites are not a good fit for WordPress?May 07, 2025 am 12:10 AM

WordPressisnotidealforhigh-trafficwebsites,customandcomplexapplications,security-sensitiveapplications,real-timedataprocessing,andhighlycustomizeduserinterfaces.Forhigh-trafficsites,useNext.jsorcustomsolutions;forcomplexapplications,optforDjangoorRub

Can you build a blog with WordPress?Can you build a blog with WordPress?May 06, 2025 am 12:03 AM

Yes,youcanbuildablogwithWordPress.1)ChoosebetweenWordPress.comforbeginnersorWordPress.orgformorecontrol.2)Selectathemetopersonalizeyourblog'slook.3)Usepluginstoenhancefunctionality,likeSEOandsocialmediaintegration.4)Customizeyourthemewithsimplecodetw

How secure is WordPress as a CMS platform?How secure is WordPress as a CMS platform?May 05, 2025 am 12:01 AM

WordPresscanbesecureifmanagedproperly.1)KeeptheWordPresscoreupdatedtopatchvulnerabilities.2)Vetandupdatepluginsandthemesfromreputablesources.3)Enforcestrongpasswordsandusetwo-factorauthentication.4)Chooseahostingproviderwithgoodsecuritypractices.5)Ed

What kind of websites can you build with WordPress CMS?What kind of websites can you build with WordPress CMS?May 04, 2025 am 12:06 AM

WordPresscanbuildvarioustypesofwebsites:1)Personalblogs,easytosetupwiththemesandplugins.2)Businesswebsites,usingdrag-and-dropbuilders.3)E-commerceplatforms,withWooCommerceforseamlessintegration.4)Communitysites,usingBuddyPressorbbPress.5)Educationalp

What are the pros and cons of using WordPress as your CMS?What are the pros and cons of using WordPress as your CMS?May 03, 2025 am 12:09 AM

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

How does WordPress compare to other popular CMS platforms?How does WordPress compare to other popular CMS platforms?May 02, 2025 am 12:18 AM

WordPressexcelsineaseofuseandadaptability,makingitidealforbeginnersandsmalltomedium-sizedbusinesses.1)EaseofUse:WordPressisuser-friendly.2)Security:Drupalleadswithstrongsecurityfeatures.3)Performance:GhostoffersexcellentperformanceduetoNode.js.4)Scal

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools