3

I've completed my install using wp-cli. Right now the server is only available within my organization's VPN and the domain (say, foo.org) is being used by the existing (non-WordPress) site that will be decommissioned once this new WordPress site is ready.

When I installed WordPress, I set the url to the domain we plan to use once the website is ready (foo.org). While under development, the website will be accessed in the browser at its IP address (say, 192.168.0.0).

This leads to a problem where none of the assets load when I visit the site at https://192.168.0.0. For example, it tries to find the stylesheet at this non-existent address:

From a cursory Google search, I gather there is some technical reason why WordPress doesn't use relative URLs for these assets.

With that, is there an established convention or best practice for dealing with this situation?

4

I normally just map my hosts file to the correct IP. This would work if you were only wanting to work on a site from your box only.

Only benefit to this option, as opposed to others, is that you wouldn't need to change any of your Wordpress settings to go live.

  • Good suggestion. One issue with this approach, which should have been clarified in this question, is that other non-technical users within the VPN need to access the site while it is under development. – Chapman Atwell Feb 7 '17 at 20:58
  • Ahh yes. That does make the difference! Then I personally like your wp-config answer. That way you only have to change it in one place. – Samyer Feb 8 '17 at 16:10
1

One quick fix seems to be to simply hardcode the URL in the wp-config.php file. Following the documentation in the Codex, I added these two lines to the top of wp-config.php

define('WP_HOME','https://192.168.0.0');
define('WP_SITEURL','https://192.168.0.0');

Then, once the site is ready for release, I expect I can just update these as follows:

define('WP_HOME','https://foo.org');
define('WP_SITEURL','https://foo.org');

Any unintended consequences to this approach that I should note?

  • I usually update htaccess with the temporary url or IP address and then update wp-options with this change too, then change back for golive. Have you tried this? – Nathaniel Flick Feb 7 '17 at 20:26
  • @NathanielFlick I have not tried this. Any advantages to this approach over what I suggested? – Chapman Atwell Feb 7 '17 at 21:00
  • Yes because this is the normal way to set the url (htaccess plus database/wp-options update). I use this when I develop locally, on a staging site, and on a live site and set to each environment. Also there is a good reason for not doing it this way as illustrated on the codex: codex.wordpress.org/Changing_The_Site_URL "This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method. " – Nathaniel Flick Feb 8 '17 at 10:02
  • See my Answer I've just added. – Nathaniel Flick Feb 8 '17 at 11:40
1

I want to post my comment as an answer so it's more helpful.

The normal way to set the url (htaccess plus database/wp-options update) is to set the url in .htaccess and also wp-options table for home and site urls.

There is a good reason for not doing it in wp-config, as is mentioned on the WordPress Codex site:

This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method.

This makes sense after you move a few sites; anything you can do to make this easier you will do. :)

Edit: add actual code for .htaccess, then wp-config.php:

# BEGIN WordPress
# You will need to edit this to suit your server location
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

In your database, go to wp_options table and find "Site URL" and "Home URL" (they are near the top when you open phpmyadmin) and change those to the url you want to render.

If you have to update your hosts file you will need to point to the url you want your website to render to as you did in wp-options step above.

  • Thanks for adding this answer. Would you mind spelling out the steps for updating .htaccess and the wp-options table? I'd like to give this a try and if it works for me, I'll choose it as best answer. – Chapman Atwell Feb 8 '17 at 18:49
  • Hi Chapman I don't know your actual settings but I can point you to the WordPress codex docs for htaccess codex.wordpress.org/htaccess and change wp-options for Site and Home urls to your new domain. Example here: inmotionhosting.com/support/website/wordpress/… – Nathaniel Flick Feb 9 '17 at 18:52
  • Nathaniel, the two links you mention appear to cover multiple cases. To make life easier on myself and future readers, can you include a sample .htaccess file in your answer? (You can assume domain I use in question, foo.org.) For wp-options table changes, you're saying these can be changed in dashboard by admin? – Chapman Atwell Feb 10 '17 at 16:55
  • Yes they cover multiple cases but I highlighted which ones pertain to your situation. I'll edit my answer again to show this more exactly, but I can't do it for your particular case. This is a fundamental WordPress function, setting up htaccess and wp-config which is why I linked you to the codex for more information. – Nathaniel Flick Feb 13 '17 at 21:13
0

I've found the easiest way is to change the domain name value in the wp_options table to the local IP address of the site. You can then test the site until the domain name is ready.

When you are ready to go live, just go back into the wp_options table and change the URLs to the domain name (from the IP address that you used in testing. There are two locations for that, easily found.

  • Don't forget to also change htaccess. – Nathaniel Flick Feb 8 '17 at 10:31
  • See my answer I've just added. – Nathaniel Flick Feb 8 '17 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.