Rescue a WordPress Install With Incorrect URL Settings

This post is in the category: Tips

Random small break-fix or enlightening ideas

When moving existing WordPress installs around, you may find that the site becomes inaccessible because the site URL is contained in the database table, wp_options to be exact. In order to make this site accessible, the site URL option needs to be changed. Where can that be changed? From the admin center. On the website. Yeah, it’s a catch 22. But, there are several alternative ways to change this option, even if your blog is not accessible.

Edit wp-settings.php

Personally, I think this is where the option should be stored. When you’re changing the URL, chances are the blog is either not accessible over HTTP now or won’t be after this change is made. Any settings that break/fix HTTP access shouldn’t be configured in a web page. Anyway, enough opinion, here is how to do it.

Open up wp-config.php and add these lines towards the top.


Note that changing this only overrides what is stored in the database – it doesn’t change it. If you were to add these settings and take a peak at the admin center, it will look like this.

Wordpress blog settings in wp-config.php

WordPress blog settings in wp-config.php

Those fields are disabled and showing what is configured in the flat file. You can leave it like this and know that the option is to be changed in the file the next time the blog is moved.

Edit the Database

UPDATE `wp_options` 
SET 'option_value` = 'http://a16-lamp-wp' 
WHERE `option_name` = 'siteurl' || `option_name` = 'home' LIMIT 2;

Some things to note about this query:

  • Replace ‘newurl’ with your site’s new URL
  • The limit is there to prevent massive row updates in the event the conditions are missing or something else happens to where several rows are selected.
  • If you did not use the default table prefix, your table name will be different.

After running this query, try and load the site again. Then go to /wp-admin and into Settings -> General to verify the updates, however, the fact that you can view this page should confirm that the updates were successful.

Edit Theme functions.php

This is a setting that should be used temporarily and then removed.

Drop these lines in your theme’s functions.php file.


This code will actually update the settings in the wp-settings table, so you only need to stick it there for a couple page loads and then remove it.

This entry was posted in Tips on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

Leave a Reply

Your email address will not be published. Required fields are marked *