Categories
Changing The Site URL
TOPICS
On the Settings -> General screen in a single site installation of WordPress, there are two fields named “WordPress Address (URL)” and “Site Address (URL)”. They are important settings, since they control where WordPress is located. These settings control the display of the URL in the admin section of your page, as well as the front end, and are used throughout the WordPress code.
- The “Site Address (URL)” setting is the address you want people to type in their browser to reach your WordPress blog.
- The “WordPress Address (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.
Changing the Site URL #Changing the Site URL
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
Edit wp-config.php #Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where “example.com” is the correct location of your site.
This is not necessarily the best fix, it’s just hard-coding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.
Top ↑
Edit functions.php #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.
- 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 and upload it back to the site.
- Add these two lines to the file, immediately after the initial “<?php” line:
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.
Important! Do not leave this code in the functions.php file. Remove them after the site is up and running again.
Note: If your theme doesn’t have a functions.php file create a new one with a
text editor. Add the <?php tag and the two lines using your own URL instead of example.com:
<?php
update_option( 'siteurl', '
http://example.com' );
update_option( 'home', '
http://example.com' );
Upload this file to your theme directory. Remove the lines or the remove the file after the site is up and running again.
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

ort/yourblog ');
update_option( 'home', 'http://your.site.url

ort/yourblog ');[
refresh your web browser using your external site URL:
http://your.site.url

ort/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

ort/yourblog from a LAN browser brings the page up correctly.
Top ↑
Relocate method #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.
Code function #Code function
When RELOCATE has been defined as true in wp-config.php (see next chapter), the following code in wp-login.php will take action:
1
2
3
4
5
6
7
8 | if ( defined( 'RELOCATE' ) AND RELOCATE ) {
// Move flag is set
if ( isset( $_SERVER['PATH_INFO'] ) AND ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], "", $_SERVER['PHP_SELF'] );
$url = dirname( set_url_scheme( 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
if ( $url != get_option( 'siteurl' ) )
update_option( 'siteurl', $url );
} |
Top ↑
Steps #Steps
- Edit the wp-config.php file.
- 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);
- Save your wp-config.php file.
- 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.yourdomainname.com, then type http://www.yourdomainname.com/wp-login.php into your browser’s address bar.
- Login as per normal.
- 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.
- 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. You’ll still need to alter those manually.
Important! Leaving the RELOCATE constant in your wp-config.php file is insecure, as it allows an attacker to change your site URL to anything they want in some configurations. Always remove the RELOCATE line from wp-config.php after you’re done.
Top ↑
Changing the URL directly in the database #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 your site 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 the wp_options table.
- Under the field option_name, scroll down and look for siteurl.
- Click the Edit Field icon which usually is found at the far left at the beginning of the row.
- The Edit Field window will appear.
- In the input box for option_value, carefully change the URL information to the new address.
- Verify this is correct and click Go to 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 Go to save the information.