wiki:how-to/wordpress/change-site-url

Version 1 (modified by JaimeV, 15 months ago) (diff)

--

The official wordpress documentation recommends several valid methods of changing your site url.

https://codex.wordpress.org/Changing_The_Site_URL

If you still have access to the wordpress admin interface for your site under the "Settings->General" screen changing the values of the two fields named "WordPress Address (URL)" and "Site Address (URL)" is the easiest way to do this.

However if you do not have access to the admin interface or want to be sure that this value is changed everywhere in your site we recommend using the [ https://github.com/wp-cli/wp-cli ] utility which we've installed on all of our standard servers for you. You will need to access the command line [ https://support.mayfirst.org/wiki/faq/security/secure-shell | via ssh ] to use this tool.

Once you have access to the server you can navigate using the change directory command cd to your web folder or the folder that contains your wordpress installation before invoing the wp-cli utility with the command {{{wp}}.

wp-cli can both check and directly set the siteurl configuration value from the command line.

0 siteuser@server:~/sitename.org/web$ wp option get siteurl

http://sitename.org

In this example we will replace http with https for the site.

0 siteuser@server:~/sitename.org/web$ wp option set siteurl https://sitename.org

The wp-cli utility can also search and replace any instances of a string in your database to replace text embedded in posts and other configuration fields in your site that might still be pointing to the old url.

This example uses the --dry-run argument to test without making any real changes. Remove the --dry-run argument and run again to make those changes effective.

0 siteuser@server:~/sitename.org/web$  wp search-replace --dry-run http://sitename.org https://sitename.org --skip-columns=guid

You may also choose to use the same method to ensure other versions of the url that might exist in your site. Below are just a couple of examples

0 siteuser@server:~/sitename.org/web$  wp search-replace  --dry-run  http://www.sitename.org https://sitename.org --skip-columns=guid
0 siteuser@server:~/sitename.org/web$  wp search-replace  --dry-run  http://oldsitename.org https://sitename.org --skip-columns=guid