Title: wp_options siteurl vs wp-config
Last modified: January 7, 2019

---

# wp_options siteurl vs wp-config

 *  [mattpr](https://wordpress.org/support/users/mattpr/)
 * (@mattpr)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/wp_options-siteurl-vs-wp-config/)
 * Running WP 5.0.2 with mysql on Ubuntu 16.04.
 * I auto-deploy my personal WP installs and set the siteurl via the wp-config method:
 *     ```
       define( 'WP_HOME', 'http://example.com' );
       define( 'WP_SITEURL', 'http://example.com' );
       ```
   
 * Recently I noticed that while accessing the site via example.com, I was getting
   random errors. All image requests would redirect and lots of cross-site security
   errors. I have a second domain (say example2.com) that redirects to example.com…
   but the site should run under example.com only.
 * Originally when I setup the site I was going to use example2.com as the primary…
   but changed my mind and updated the provisioning scripts to use example.com instead.
 * so wp-config.php originally had WP_HOME/SITEURL set to example2.com and then 
   was changed to example.com.
    The database (`SELECT * FROM wp_options WHERE option_name
   ='siteurl';`) is set to use example2.com still and certain types of generated
   URLs (e.g. for image resources) are using the url from the database as the baseurl
   instead of the url from wp-config.php.
 * So the site runs under example.com but a lot of resources are requested from 
   example2.com…which redirects to example.com so you don’t notice at first…but 
   lots of little problems quickly become apparent.
 * Is this a bug or do I just not understand the precedence of various settings.
 * The UI (Settings>General) have siteurl/home text fields greyed out and show the
   values from wp-config.php…but the database doesn’t reflect that.
 * Of course I can just add a little mysql to my provisioning to make sure that 
   database field is getting updated…but seems like the values in wp-config should
   take precedence and/or cause the db config to be updated.
 * Same issue for home option.
    `SELECT * FROM wp_options WHERE option_name='home';`
    -  This topic was modified 7 years, 3 months ago by [mattpr](https://wordpress.org/support/users/mattpr/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwp_options-siteurl-vs-wp-config%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/wp_options-siteurl-vs-wp-config/#post-11059897)
 * From [the codex](https://codex.wordpress.org/Editing_wp-config.php):
 * > Setting this value in wp-config.php overrides the wp_options table value for**
   > siteurl**. Adding this in can reduce the number of database calls when loading
   > your site.
 * So by defining `WP_SITEURL` you are overwriting the value in the database. The
   URL in the constant and the database are used for the same thing.
 * If you are seeing requests to images from a different URL then they are probably
   images in posts that were saved before the URL was changed. When you add an image
   to a post, the full URL of the images is saved, and this URL does not change 
   when you use the constant or change the database setting.
 * To change old URLs inside your content you need to do a search and replace in
   the database. See [this section of the codex](https://codex.wordpress.org/Moving_WordPress#Changing_Your_Domain_Name_and_URLs)
   for options.
 *  Thread Starter [mattpr](https://wordpress.org/support/users/mattpr/)
 * (@mattpr)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/wp_options-siteurl-vs-wp-config/#post-11060237)
 * Thanks for the quick reply.
 * The site/home change was made before the site was launched. No pages, no posts,
   no images.
 * Many of the errors are related to cross-site scripting issues…with wordpress 
   javascript being loaded from the old domain rather than new domain.
 * This change was made months ago and we just started working on the site…but I
   also did cache/cookie clearing just to make sure.
 * I confirmed with mysql that the value in the database for siteurl and home were
   the old values and did not reflect what was in wp-config.php. ie the db never
   gets updated when values are set in wp-config.php. Then the problem arises because
   it seems that wp uses the db value instead of the value in wp-config?
 * Updating these values manually in the database to the correct values resolved
   all the problems immediately.
 * Hence I figure it is a bug of some sort. Would expect either:
 * – if vars are set in wp-config.php, then db values are ignored or
    – db value
   is used globally, but when vars are set in wp-config.php the db value is updated.
 * I am guessing most wp users are just setting this in the db via the Settings>
   General page…which I am guessing isn’t broken.
 * One more thought… I am appending these defines to wp-config.php via my provisioning
   scripts. Perhaps being included after the `require_once` for wp-settings.php 
   causes an issue? Maybe wordpress is functioning as expected and my defines just
   aren’t getting picked up from wp-config for some reason? I wouldn’t think the
   order of the defines in that file would matter so much but that would also explain
   it. On the other hand…the Settings>General page shows the home/siteurl boxes 
   greyed out and shows the values from wp-config.php and not from the db. So still
   think there is something wrong here.
 *     ```
       /* ... */
       /** Sets up WordPress vars and included files. */
       require_once(ABSPATH . 'wp-settings.php');
       define('WP_HOME', 'http://www.example.com');
   
       define('WP_SITEURL', 'http://www.example.com');
       /* EOF */
       ```
   
 * The original install was done with whatever the latest stable WP was on October
   29. Just checked: 4.9.8. The domain change was shortly thereafter. I did the 
   upgrade to 5.0.2 this week (from wp-admin UI) before we started developing the
   site content. So possible this is a bug from a pre5 release.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_options siteurl vs wp-config’ is closed to new replies.

## Tags

 * [siteurl](https://wordpress.org/support/topic-tag/siteurl/)
 * [wp-config](https://wordpress.org/support/topic-tag/wp-config/)
 * [wp_options](https://wordpress.org/support/topic-tag/wp_options/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [mattpr](https://wordpress.org/support/users/mattpr/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/wp_options-siteurl-vs-wp-config/#post-11060237)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
