From: http://codex.wordpress.org/Changing_The_Site_URL
On the Settings->General screen in a single site installation of WordPress, there are two fields named “WordPress address (URL)” and “Site address (URL)”. These are also known as the “Home” and “Site URL” settings. They are important settings, since they control where WordPress thinks your site is located. They control the display of the URL in the admin section of your page as well as the front end, and are used through out the WordPress code. The “Home” setting is the address you want people to type in their browser to reach your WordPress blog. The “Site URL” setting is the address where your WordPress core files reside. *Note: Both settings should include the http:// part and should not have a slash”/”at the end.
Every once in a while, somebody finds a need to manually change (or fix) these settings. Usually this happens when they change one or both and discover that their site no longer works properly. This can leave the user with no easily discoverable way to correct the problem. This article tells you how to change these settings directly.
Additional information is presented here for the case where you are moving WordPress from one site to another, as this will also require changing the site URL. You should not attempt to use this additional information if you’re only attempting to correct a”broken”site.
**Alert! These directions are for single installs of WordPress only. If you are using WordPress MultiSite, you will need to manually edit your database.
Contents
1 Changing the Site URL
1.1 Edit wp-config.php
1.2 Edit functions.php
1.3 Relocate method
1.3.1 Steps
1.4 Changing the URL directly in the database
2 Moving Sites
2.1 Altering Table Prefixes
2.2 Changing Template Files
2.3 Changing the Config file
2.4 Verify the Profile
2.5 Changing the .htaccess file
2.6 Additional items of note
2.6.1 Important GUID Note
2.7 Multi-site notes
1 Changing the Site URL
There’re four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
1.1 Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to yourwp-config.php, where”example.com”is the correct location of your site.
define(‘WP_HOME’,’http://example.com’);
define(‘WP_SITEURL’,’http://example.com’);
This is not necessarily the best fix, it’s just hardcoding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.
1.2 Edit functions.php
If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.
(1) FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor (like notepad) and upload it back to the site.
(2) Add these two lines to the file, immediately after the initial “<?php” line.
update_option(‘siteurl’,’http://example.com/blog’);
update_option(‘home’,’http://example.com/blog’);
Use your own URL instead of example.com, obviously.
(3) Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly; if you can use that, do so.
(4) Load the login or admin page a couple of times. The site should come back up.
(5) Repeat the above steps, but remove those lines. *IMPORTANT: Do NOT leave those lines in there. Remove them immediately after the site is up and running again.
If there is no functions.phpfile in the theme, Create a new text file called “functions.php”. Edit it with notepad, and add this text to it, using your own URL instead of example.com
<?php
update_option(‘siteurl’,’http://example.com/blog’);
update_option(‘home’,’http://example.com/blog’);
?>
Upload that to your theme directory, then proceed as stated above. Remove the file afterwards.
>>>
Here are some additional details that step you through transfering a LAN-based wordpress site into an externally accessible site as well enabling editing the wordpress site from inside the LAN.
Two important keys are router/firewall modifications and the “wait 10+ minutes” after making the changes at the end.
-using ssh to log into your server (nano is a server preinstalled text editor)
-$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
-add lines just after <?php
update_option(‘siteurl’,’http://your.site.url:port/yourblog’);
update_option(‘home’,’http://your.site.url:port/yourblog’);
-refresh your web browser using your external site url http://your.site.url:port/yourblog
-$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
-remove those lines you just added (or comment them out)
-access your router (these steps are for pfSense, other routers should have similar settings to look for/watch out for)
-add to firewall/nat table a line like this: wan/tcp/port/LAN.server.IP/80
-add to firewall/rules table a line like this: tcp/*/port/LAN.server.IP/port/*
-uncheck the box at System/advanced/network address translation/Disable NAT Reflection
“Disables the automatic creation of NAT redirect rules for access to your public IP addresses from within your internal networks. *Note: Reflection only works on port forward type items and does not work for large ranges >500 ports.”
Then go do something for ten minutes and when you get back see if the external url http://your.site.url:port/yourblog from a LAN browser brings the page up correctly.
1.3 Relocate method
WordPress supports an automatic relocation method intended to be a quick assist to getting a site working when relocating a site from one server to another.
1.3.1 Steps:
(1) Edit the wp-config.php file.
(2) After the”define”statements (just before the comment line that says “That’s all, stop editing!”), insert a new line, and type:
define(‘RELOCATE’,true);
(3) Save your wp-config.php file.
(4) Open a web browser and manually point it to wp-login.php on the new server. For example, if your new site is at http://www.mynewdomain.com, then type http://www.mynewdomain.com/wp-login.php into your browser’s address bar.
(5) Login as per normal.
(6) Look in your web browser’s address bar to verify that you have, indeed, logged in to the correct server. If this is the case, then in the Admin back-end, navigate to Settings>General and verify that both the address settings are correct. Remember to Save Changes.
(7) Once this has been fixed, edit wp-config.php and either completely remove the line that you added (delete the whole line), comment it out (with //) or change the true value to false if you think it’s likely you will be relocating again.
*Note:When the RELOCATE flag is set to true, the Site URL will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. Those you will still need to alter manually.
Changing the URL directly in the database
1.4 Changing the URL directly in the database
If you know how to access phpMyAdmin on your host, then you can edit these values directly to get you up and running again.
Backup your database and save the copy off-site.
Login to phpMyAdmin.
Click the link to your Databases. A list of your databases will appear.
Choose the one that is your WordPress database. All the tables in your database will appear on the screen.
From the list, look for wp_options. *Note:The table prefix of wp_ may be different if you changed it when installing.
Click on the small icon indicated as Browse. A screen will open with a list of the fields within thewp_optionstable.
Under the field option_name, scroll down and look for siteurl.
Click the Edit Fieldicon which usually is found at the far left at the beginning of the row. The Edit Fieldwindow will appear.
In the input box for option_value, carefully change the URL information to the new address.
Verify this is correct and click Goto save the information.
You should be returned to your wp_options table. 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.
In the input box for option_value, carefully change the URL information to the new address.
Verify this is correct and click Goto save the information.
2 Moving Sites
When moving sites from one location to another, it is sometimes necessary to manually modify data in the database to make the new site URL information to be recognized properly. Many tools exist to assist with this, and those should generally be used instead of manual modifications.This is presented here as information only. This data may not be complete or accurate.You should read the Moving WordPress article first, if attempting to move WordPress from one system to another.
2.1 Altering Table Prefixes
Like many WordPress administrators, you may be running several WordPress installations off of one database using various wp-config.php hacks. Many of these hacks involve dynamically setting table prefixes, and if you do end up altering your table prefix, you must update several entries within the prefix_usermeta table as well.As in the above section, remember that SQL changes are permanent and so you should back up your database first.
If you are changing table prefixes for a site, then remember to alter the table prefix in the user meta tables as well. This will allow the new site to properly recognize user permissions from the old site.
UPDATE `newprefix_usermeta` SET `meta_key` = REPLACE( `meta_key` ,’oldprefix_’,’newprefix_’);
2.2 Changing Template Files
In yourWordPress 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 Administration>Settings>Generalpanel. The tag in your template files will not have to be modified.
2.3 Changing the Config file
You will need to update your WordPress configuration file if your database has moved or changed in certain ways.
You will only need to modify the config file if your database has moved to another server and is not running on your localhost, you have renamed your database,you have changed the database user name
Make a backup copy of your wp-config.php file.
Open the wp-config.php file in a text editor.
Review its contents. In particular, you are looking for the database host entry.
Save the file.
At this point, your WordPress blog should be working.
2.4 Verify the Profile
In your Administration Panels go to Settings>General. Here you will verify that the changes you made in Changing the URL above, are correct.
Verify that the reference in your WordPress URL contains the new address.
Verify that the reference in your “Blog URL” contains the new address.
If you have made changes, click Save Changes.
2.5 Changing the .htaccess file
After changing the information in your Administration>Settings>Generalpanel, you will need to update your .htaccess file if you are using Permalinks or any rewrites or redirects.
Make a backup copy of your .htaccess file. This is not a recommendation but a requirement.
Open the .htaccess file in a text editor.
Review its contents, looking for any custom rewrites or redirects you entered.
Copythese to another text file for safe keeping.
Close the file.
Follow the instructions on the Permalinks SubPanel for updating your Permalinks to the .htaccess file.
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.
Make any changes necessary in those custom rewrites and redirects to reflect the new site address.
Save the file.
Test those redirects to ensure they are working.
If you make a mistake, you can Restoring Your Database From Backup from your backup and try this again. So make sure it is right the first time.
2.6 Additional items of note
There are other things you may wish to change in order to correct URLs when moving sites.
Images link: image links are stored in “post_content” in the wp_posts table. You can use the similar code above to update image links.
wp_options: Besides the “siteurl” and “home” items mentioned above, there are other option_value which also need revision, such as “upload path”, and some plugin items (depends on what you’ve installed, such as widgets, stats, DMSGuestbook, sitemap, etc.)
Do a FULL database search for any items left. MAKE SURE you know what you are changing. and go through each item for possible improper replacement
If you a running a network have multiple sites, you will need to replace instances of the URL in the database. They are stored in many tables, including each one of the sites (blogs). Be careful in what you replace and be sure you know the meaning of the field before changing it. See the Important GUID note below for an example of what not to change.
How To: Move YourWordPressBlog to a New Domain- Using the Export/Import feature to move a blog to a new domain
2.6.1 Important GUID Note
When doing the above and changing the URLs directly in the database, you will come across instances of the URL being located in the “guid” column in the wp_posts tables. It is critical that you do NOT change the contents of this field. The term “GUID” stands for “Globally Unique Identifier”. It is a field that is intended to hold an identifier for the post which (a) is unique across the whole of space and time and (b) never, ever changes. The GUID field is primarily used to create the WordPressfeeds. When a feed-reader is reading feeds, it uses the contents of the GUID field to know whether or not it has displayed a particular item before. It does this in one of various ways, but the most common method is simply to store a list of GUID’s that it has already displayed and “marked as read” or similar. Thus, changing the GUID will mean that many feedreaders will suddenly display your content in the user’s reader again as if it was new content, possibly annoying your users. In order for the GUID field to be “globally” unique, it is an accepted convention that the URL or some representation of the URL is used. Thus, if you own example.com, then you’re the only one using example.com and thus it’s unique to you and your site. This is why WordPress uses the permalink, or some form there of, for the GUID. However, the second part of that is that the GUID must never change. Even if you shift domains around, the post is still the same post, even in a new location. Feed readers being shifted to your new feeds when you change URLs should still know that they’ve read some of your posts before, and thus the GUID must remain unchanged. Never, ever, change the contents of the GUID column, under any circumstances.
2.7 Multi-site notes
In Multi-site, when you change domains, you must change values in two database tables,not just one wp_blogs.
you must update the “domain” column for each site (if you really want to get ambitious, you can make them different for different sites). wp_#_options (and wp_options for the main site): domain name also is in two properties in wp_<blog_number>_options: “siteurl” and “home” (for main site, you also have to change a property in the wp-config.php file – DOMAIN_CURRENT_SITE).
Then, once you have changed and tested these domain name changes, you need to go through all the tables in the database and clean up references to your old domain name.
This list isn’t exhaustive, but these tables can contain URLs that might need to be changed:
wp_#_commentmeta (and wp_commentmeta)
wp_#_comments (and wp_comments)
wp_#_options (and wp_options)
wp_#_posts (and wp_posts)
wp_bp_activity
wp_users
When searching for old URLs to replace, use the Search&Replace Plugin. If you select the “All – only search!” check box, you can use it to do a read-only search of all tables (even ones that it won’t allow you to select for replace) for your old domain. Make sure to search not only for the address,”
http://<old_domain>”, but also for just the domain,”<old_domain>”, since some of the database columns will contain the domain without the”http://”.
Then, once you’ve found what you have to change, use the following SQL as a sample for updating each column where there are values that contain your old domain, one at a time, and only the rows where your old domain is present in a given value (this sample is a query to update option values that reference your old domain):
UPDATE wp_#_options SET option_value = REPLACE ( option_value,'<old_domain>’,'<new_domain>’) WHERE option_value LIKE'<old_domain>’
WHERE:
# = ID of site within multi-site.
<old_domain>= string value of your old domain
<new_domain>= string value of your new domain
You will have to do this for each site, and for tables that contain data about all sites. The Search and Replace Plugin should at least find all the tables and columns you need to update, though.
Also, the Search and Replace Plugin has the potential to be dangerous. It is probably a good idea to only install it while you need it, and then to delete it so it can’t be used by accident.