Removing hard coded site URL from wp-config

After the IP address of my WordPress site had changed,
I had to hard code its address in wp-config.php:

define('WP_HOME','http://54.77.99.66');
define('WP_SITEURL','http://54.77.99.66');

When I delete the lines in wp-config.php, my site is no longer accessible.

Read More

How can I get rid of the hard coded entries and set my site’s address in the UI (which is currently greyed out)?

Related posts

Leave a Reply

2 comments

  1. I routinely move sites between domains as I test features, restore and test backups, etc. and I always just change the domain throughout the database. The problem with this approach is that many options are store in MySQL as serialized PHP arrays which include the length of a string as a value so you can’t just perform a blind search and replace. However, a company called interconnect/it has a free product called Search Replace DB that is able to safely traverse and update these arrays. I say “safely” in that I’ve run it hundreds of times without issue but they still always recommend backing up your database first.

    1. First download the software above, extract it locally and upload the folder to your server
    2. Using your browser navigate to the folder that you’ve uploaded
    3. In the search box enter your old site’s domain
    4. In the replace box enter your new site’s domain
    5. In the database area enter your WP database information
    6. Press the dry run button just to see what the tool thinks should be updated. You’ll usually see one or two items in wp_options and a bunch in wp_posts and wp_postmeta. If you have blog wp_comments might get some updates. Depending on your plugins you might get others, too. You can even click the view changes links to see what it thinks it should update.
    7. If this looks good you can hit the live run button and let it perform the updates.
    8. Delete when done. Very important. I’ll say it again. Delete when done.

    There are some things to be aware of when replacing text. If my site is example.net and my email address is chris@example.net and I perform a replace on just example.net it will change my email address, too. If my site is www.example.net (with the WWW) then I would search on www.example.net which wouldn’t catch. I always audit the users just to make there aren’t any domain conflicts. If there are, I just perform the above steps a second time, once for each user to change the email addresses back, but this is pretty rare.

    The other thing to watch is text-based content about your domain. For instance, if you are keeping your old domain at example.net and spinning off a blog at example.com, the latter might have a blog post about how awesome products are at the former but the replace would point to the latter.

    These are the only two edge cases that I’ve ever run into with this tool, however. Using this tool you should be able to avoid the WP_HOME and WP_SITEURL constants completely.

    Also, just in case you are worried, the actual WordPress codex even references and recommends this product.

  2. This seems to work for me. Honestly not sure how it works:

    define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
    define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
    

    I guess it does ‘http://<yoursite>‘ where <yoursite> is replaced with whatever the address of the server is in your URL bar. Doing this, I can access my site both locally (i.e. via the local IP) and from other networks without issue.