Sometimes the URL or domain for a WordPress site is no longer appropriate. This could be for several reasons. Perhaps everything was setup using a different domain (like localhost) for testing purposes. Maybe, it was installed in a folder and now needs to shine at the root of the site. Maybe the domain has been penalized as spammy by major search engines but the content still has value. Or maybe the URL wasn’t very well thought out and rebranding needs to occur. Or maybe it simply needs to be moved over to a “/blog/ folder. Whatever the reason for the URL change, there are a few steps involved in making it happen.
One thing to keep in mind: A lot of times URLs are hardcoded in the database for media uploads and internal linking, or plugins or themes may do that as well. All those instances will have to be changed as well, and often require direct database editing.
For Domain Changes an Extra Step is Required
If changing the domain, it’s mandatory that the server is aware of the domain as well. If it’s the main domain for the hosting account, this might require a ticket to be put in with the hosting provider in order to be accomplished. Or it may require just a simple move of the content (or backup of files and database), and then typing the new domain in a field. It will be different for different hosts. Check with their help files or support steps for assistance.
If it’s an add-on (or secondary) domain, then it’ll need to be setup and pointed to the existing installation folder on the server. Then the domain itself will need to have the name servers changed to point to the server.
To add an add-on domain, if using CPanel, perform the following steps:
- Login to your hosts’s CPanel.
- Scroll down to the Domains section and click on Addon Domains.
- Type in the domain name in the New Domain Name: box.
- Specify the Document Root in relation to the “home” folder.
- Create a password (which can be used for the main FTP user for that particular site – it may never be used though, as the FTP account for the main hosting account is often used to gain access).
- Click the Add Domain button.
Make sure the site is either moved to, or still resides at, the location selected on the server. Also make sure the Name Servers are set for that domain at the domain registrar. To get the two name server values to use, go back to the home screen of the CPanel, and scroll down to the bottom left side and locate the Account Information box. The server values are in there.
Option 1: First Try Changing the Necessary Values for the URL Switch from the WordPress Dashboard if you Are Able to Gain Access
Many times a simple change can take care of the URL switch. If you have access to your WordPress dashboard, you may be able to make the change to the URL right in there. If so, head to Settings >> General. Then modify the “WordPress Address (URL)” and “Site Address (URL)” values appropriately. Unless installing WordPress into a subfolder, these values are generally set the same.
Option 2: Hard Coding the Change in wp-config.php
If you cannot access the WordPress dashboard, these values can be hardcoded into the “wp-config.php” file. This file will exist in the root of the WordPress installation. It can be downloaded by FTP (or the Control Panel’s File Manager). Depending on the tool used, it might be able to be modified directly. Create a backup somewhere before modifying. This approach isn’t ideal as it makes it so the values found on the General Settings have no meaning. The values, if existing in the “wp-config.php” file will take precedence. At any rate, if it is necessary, use the following commands to change the values.
Option 3: Setting the Change with Temporary Commands in the Theme Functions File
A better approach to the above (editing wp-config.php) would be to make a temporary modification to the functions.php template file to change those values. This is meant to update the values in the database, which in turn reflects the correct values shown in the “General Settings” area.
You can access the existing functions.php file from FTP or some other method. It should be located in the “/wp-content/themes/CURRENT-THEME/” folder. Naturally, “CURRENT-THEME” in that path is the folder for the theme currently being used. If functions.php doesn’t exist, you can create it with a text editor. If so, do a File >> Save As… and put the full file name in with the .php extension.
Either way, this is a temporary change to this file and should be removed after the change is successful.
Within an existing functions.php file, add the following lines just after the first instance of “<?php” seen in the file (near or at the top).
When creating a NEW functions.php file, add the following:
<?php update_option('home','http://new-location-example.com'); update_option('siteurl','http://new-location-example.com'); ?>
Save the file and upload it, overwriting the existing file (if exists). Make sure you have a backup. Now, after refreshing the “/wp-login.php” page a time or two at its new location, you should be able to gain access.
Last Resort: Changing the URL Values in the Database Directly
Failing any of the above, you can change the values directly in the database itself. Now, these steps aren’t to show you how to change the new URL path from within posts, and other areas where plugins or themes (or WordPress) hardcoded the path.
If you find that some of your media or internal links in posts aren’t displaying properly, follow through the steps found in the Changing The Site URL doc in the WordPress Codex. Scroll down near the bottom of the file where you will see some SQL commands to run. Pay particular attention to the warning about the GUID values. Those are unique values that use the domain/site URL at the time of posting and should not be changed as they serve a different purpose. Even when changing the URL, in most cases (except the one noted at the above link), those values should remain in tact. If changed it will update your RSS subscribers as if all the content on your site is suddenly new again, among other factors.
Finally, the steps for modifying the database directly to change the the “WordPress Address (URL)” and “Site Address (URL)” values:
- Backup the WordPress database (either with a plugin or XML/SQL export).
- Login to CPanel and login directly to phpMyAdmin.
- Depending on your server you may need to select the database that you want to work with from the left side. All the tables within your database should appear on the left. They will have whatever prefix was set during installation. By default that would be “wp_” but yours may be different. I’ll assume “wp_” for the rest of the steps though.
- Look for “wp_options” from the list, and click it.
- By default you should be on the “Browse” tab, but if not, click the Browse icon/link near the top. You will then see a screen on the right with all of the fields within that table.
- Below the “option_name” field, look for “siteurl.” It is likely near the top unless the row has been sorted.
- Click the “Edit” icon/link which should be displayed near the far left of the row. You will be able to modify the “option_value” field now from the new screen that appears.
- Carefully make the change, verify it, and double verify it. Then click the “Go” button just below.
- Now look for “home” underneath “option_name.” It likely won’t be on the first page. Just above the list of fields you should see “Page number:” with a drop-down and some arrow buttons. Scroll through by clicking the single arrow button until you locate the “home” value (probably page 2).
- Click the “Edit” text link and modify it in the same way that you did “siteurl.”
You should now be able to visit the WordPress admin dashboard or login page at its new location. Remember, there still may be the need to manually (or with an SQL statement) modify values in the database for posts that have hardcoded media paths and internal links within them. Read through the Changing The Site URL doc to learn how and don’t skip the warnings about the GUID. It may present a problem for your existing subscribership if ignored.
Comments (3 responses)
Excellent stuff, really very helpful. I was soo much disappointed when I lost access to my site. Worked hard referred to many blogs but din’t help. Your videos were really helpful in sorting this out. Thank you very much!!
Great tips. Thanks for sharing with the community.
If your site is important enough that you don’t want to lose it, you always want to make sure you have a backup first.
Then you’ll want to proceed with the query given, which should update any incorrect URLs within your posts.
If you accidentally mess something up, you can revert back to your backup. Your host probably has a backup, but don’t rely on that… make your own just in case.