WordPress:Changing The Site URL

来自站长百科
Xxf3325讨论 | 贡献2008年6月19日 (四) 18:05的版本 (新页面: __TOC__ WordPress stores two addresses inside the database. These determine where your blog files are, and where the main index is. On a normal install, these addresses are the same. The...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

WordPress stores two addresses inside the database. These determine where your blog files are, and where the main index is. On a normal install, these addresses are the same.

There are two occasions where you will need to access the database to alter one or both of these settings:

  1. If you have tried to alter the Blog URL or WordPress URL in Options and an error has occurred.
  2. If you have moved to a domain/subdomain with a different name.

BACKUP your database before you begin and store the backup off your site server, like on your hard drive. See: WordPress:Backing Up Your Database.

Changing the URL

  1. Backup your database and save the copy off-site.
  2. Login to WordPress:phpMyAdmin.
  3. Click the link to your Databases.
  4. A list of your databases will appear. Choose the one that is your WordPress database.
  5. All the tables in your database will appear on the screen.
  6. From the list, look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
  7. Click on the small icon indicated as Browse.
  8. A screen will open with a list of the fields within the wp_options table.
  9. Under the field option_name, scroll down and look for siteurl.
  10. Click the Edit Field icon which usually is found at the far left at the beginning of the row.
  11. The Edit Field window will appear.
  12. In the input box for option_value, carefully change the URL information to the new address.
  13. Verify this is correct and click Go to save the information.
  14. You should be returned to your wp-options table.
  15. Look for the home field in the table and click Edit Field. Note There are several pages of tables inside wp_options. Look for the > symbol to page through them.
  16. In the input box for option_value, carefully change the URL information to the new address.
  17. Verify this is correct and click Go to save the information.
  18. Delete the folder wp-content/cache (this is a new folder added with WordPress 2.0).
  19. That is it.

Domain Name Change

BE VERY CAREFUL WITH THIS.

IT WILL HURT.

BACKUP YOUR DATABASE FIRST: WordPress:Backing Up Your Database.

The following is irreversible. There is no "undo" or "undelete" button. This is permanent. Be warned that it can do harm.

When moving the domain, you will need to restore the database. You then need to upload your files to their new location.

At this point, your blog will NOT work.

  1. Database
    1. Follow the guide above to alter the information in the database.
  2. Database Entries
    1. Log into WordPress:phpMyAdmin.
    2. Backup your database and save the copy off-site.
    3. Login to WordPress:phpMyAdmin.
    4. Click the link to your Databases.
    5. A list of your databases will appear. Choose the one that is your WordPress database.
    6. Look for the name of the table within your database used to hold your post information. Usually it is called wp_posts, but it may have been changed. Write it down.
    7. Clicking the Browse icon or link, open the wp_posts table.
    8. Look for the field that holds your post "guid". It is usually called guid, but it may have been changed. Write it down.
    9. Click the tab at the top for SQL.
    10. Using the information you wrote down from above and the old and new URL addresses you wish to update or search and replace within your database, type in the following (CAREFULY):
UPDATE wp_posts SET guid = REPLACE (
guid,
'http://exampleoldsiteurl.com',
'http://examplenewsiteurl.com');
    1. Make sure that the names of wp-posts and post_content match the tables and fields within your database. Change them if not.
    2. Ensure that the ONLY content you want to change are within the little single 'quotes' . Make sure EVERYTHING is spelled right and that you are sure this is correct.
    3. Review everything within the SQL input box again. Make sure it is correct. There are no second changes when you take the next action. The change is permanent.
    4. When you are sure, click Go.
    5. At the top of the screen will be generated a list of how many of the tables and fields have been changed.

Changing Template Files

In your WordPress Theme, open each template file and search for any manually entered references to your old domain name and replace it with the new one. Look for specific hand coded links you may have entered on the various template files such as the sidebar.php and footer.php.

WordPress uses a template tag called bloginfo() to automatically generate your site address from information entered in your Options panel. The tag in your template files will not have to be modified.

Changing the Config file

You will need to update your WordPress configuration file if your database has moved or changed in certain ways.

  1. You will only need to modify the config file if:
    1. your database has moved to another server and is not running on your localhost
    2. you have renamed your database
    3. you have changed the database user name
  2. "'Make a backup copy of your wp-config.php file.'"
  3. Open the wp-config.php file in a text editor.
  4. Review its contents. In particular, you are looking for the database host entry.
  5. Save the file.

At this point, your WordPress blog should be working.

Verify the Profile

  1. In your WordPress:Administration Panels go to Options > General. Here you will verify that the changes you made in Changing the URL above, are correct.
  2. Verify that the reference in your WordPress URI contains the new address.
  3. Verify that the reference in your "Blog URI" contains the new address.
  4. If you have made changes, click Update Options.

Changing the .htaccess file

After changing the information in your Options > General panel, you will need to update your .htaccess file if you are using Permalinks or any rewrites or redirects.

  1. Make a backup copy of your .htaccess file. This is not a recommendation but a requirement.
  2. Open the .htaccess file in a text editor.
  3. Review its contents, looking for any custom rewrites or redirects you entered. Copy these to another text file for safe keeping.
  4. Close the file.
  5. Follow the instructions on the Permalinks SubPanel for updating your Permalinks to the .htaccess file.
  6. Open the new .htaccess file and check to see if your custom rewrites and redirects are still there. If not, copy them from the saved file and paste them into the new .htaccess file.
  7. Make any changes necessary in those custom rewrites and redirects to reflect the new site address.
  8. Save the file.
  9. Test those redirects to ensure they are working.

If you make a mistake, you can WordPress:Restoring Your Database From Backup from your backup and try this again. So make sure it is right the first time.

Additional Information

Much of this information was taken from Podz' WordPress Guides where this topic is also discussed.

See also: How to move a WordPress blog to a new URL or domain