Publish: 2014-12-06 | Modify: 2018-09-13
Recently, a friend of mine tried to change the domain name by directly modifying it in the backend settings of WordPress. However, this caused the backend login to fail, and WordPress displayed an error message: "Cookies are blocked or your browser doesn't support them. To use WordPress, you must enable cookies."
To fully replace the domain name, simply modifying it in the settings is not enough. We also need to update the old domain name in the database with the new one. Please use the following three SQL statements to update your database. Replace "http://www.zouxiuping.com" with the old domain name and "http://www.xiaoz.me" with the new domain name.
UPDATE wp_options SET option_value = REPLACE( option_value, 'http://www.zouxiuping.com', 'http://www.xiaoz.me' ) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = REPLACE( post_content, 'http://www.zouxiuping.com', 'http://www.xiaoz.me' ) ;
UPDATE wp_posts SET guid = REPLACE( guid, 'http://www.zouxiuping.com', 'http://www.xiaoz.me' ) ;
If you still encounter the "cookies are blocked" error after completing these steps, you can solve this problem by modifying the WordPress configuration file. Find the wp-config-sample.php file in the root directory of your website, fill in the required database information, and save it as wp-config.php (make sure the format is UTF-8). Finally, upload and replace the original wp-config.php file.
// ** MySQL Settings - Your MySQL database details ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');
Final note: Changing the domain name carries some risks, and it is not recommended for beginners to perform this operation. It may cause website errors or failure to be indexed. However, it is important to perform a 301 redirect. Alternatively, you can refer to the article "WordPress Domain Name Change Precautions" for more information.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.