修改本地WordPress站点URL后无法登录,请求技术协助
Hey Josh, let’s work through this migration headache step by step—this is a super common problem when moving from a local MAMP setup to a live Bluehost server, so I’ve got you covered.
First: Fix Your Local Site’s Redirect & Login Problem
The root issue here is that when you updated the WordPress/Site URLs to your Bluehost domain, your local database and config files started pointing to the live server. That’s why you can’t log in locally (cookie domain mismatch) and get redirect errors when trying to edit config files. Here’s how to roll back the local URLs:
Method 1: Edit the Database via phpMyAdmin (Most Reliable)
Since you’re using MAMP, phpMyAdmin is already available to tweak your local database:
- Launch MAMP, start Apache and MySQL, then click "Open WebStart page". Find and open the phpMyAdmin link.
- Locate your WordPress database (check your local
wp-config.phpfile’sDB_NAMEvalue if you can’t remember the name). - Click into the database, then find the
wp_optionstable (adjust the prefix if you changed it fromwp_during setup). - Look for two rows: one with
option_nameset tositeurl, another tohome. Edit both of theiroption_valuefields to your local URL—e.g.,http://localhost/your-site-directoryor your custom MAMP local domain likehttp://local.yoursite.com. - Save the changes, close phpMyAdmin, and refresh your local site. You should now be able to access and log in without issues.
Method 2: Force Local URLs via wp-config.php
If you’d rather skip the database edit, you can hardcode your local URLs into wp-config.php to override the database settings:
- Open your local WordPress root folder’s
wp-config.phpfile in a text editor. - Add these two lines right before the
/* That's all, stop editing! Happy publishing. */comment:
define('WP_HOME','http://localhost/your-site-directory'); define('WP_SITEURL','http://localhost/your-site-directory');
- Replace the URL with your actual local site address, save the file, and refresh your local site. The redirect should stop, and you’ll be able to log in again.
Next: Do the Migration the Right Way (Avoid Future Issues)
Now that your local site is working again, let’s get it moved to Bluehost properly:
- Backup Local Files: Zip up all files in your MAMP WordPress site folder.
- Backup Local Database: Use phpMyAdmin to export your local database as a SQL file.
- Upload Files to Bluehost: Use Bluehost’s cPanel File Manager or an FTP tool to upload your zipped site files to the
public_htmlfolder (your server’s web root), then unzip them. - Set Up Bluehost Database: In Bluehost’s cPanel, create a new database, a database user, and assign full permissions to that user for the new database.
- Import Database to Bluehost: Use Bluehost’s phpMyAdmin to import your local SQL file. Then, just like you did locally, edit the
wp_optionstable’ssiteurlandhomevalues to your live Bluehost domain (e.g.,https://yoursite.com). - Update wp-config.php for Bluehost: Edit your local
wp-config.phpto use the new Bluehost database credentials (DB_NAME,DB_USER,DB_PASSWORD,DB_HOST—Bluehost usually useslocalhostfor the host). Upload this updated file to Bluehost to replace the existing one. - Fix Hardcoded Local URLs: Many themes, plugins, and posts store local URLs in the database. Run these SQL queries in Bluehost’s phpMyAdmin to replace all instances of your local URL with your live domain (adjust the table prefix and URLs as needed):
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://localhost/your-site-directory', 'https://yoursite.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://localhost/your-site-directory', 'https://yoursite.com'); UPDATE wp_options SET option_value = REPLACE(option_value, 'http://localhost/your-site-directory', 'https://yoursite.com');
If You’re Having Login Issues on the Live Bluehost Site
If after migration you can’t log into the live site, it’s likely a cookie domain mismatch. Add these lines to your Bluehost wp-config.php file:
define('COOKIE_DOMAIN', 'yoursite.com'); define('COOKIEPATH', '/'); define('SITECOOKIEPATH', '/');
Replace yoursite.com with your actual domain, clear your browser’s cache and cookies, then try logging in again.
内容的提问来源于stack exchange,提问作者Josh L.

