| | 1 | The official wordpress documentation recommends several valid methods of changing your site url. |
| | 2 | |
| | 3 | https://codex.wordpress.org/Changing_The_Site_URL |
| | 4 | |
| | 5 | 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. |
| | 6 | |
| | 7 | 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. |
| | 8 | |
| | 9 | 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}}. |
| | 10 | |
| | 11 | wp-cli can both check and directly set the siteurl configuration value from the command line. |
| | 12 | |
| | 13 | {{{ |
| | 14 | 0 siteuser@server:~/sitename.org/web$ wp option get siteurl |
| | 15 | |
| | 16 | http://sitename.org |
| | 17 | }}} |
| | 18 | |
| | 19 | In this example we will replace http with https for the site. |
| | 20 | |
| | 21 | {{{ |
| | 22 | 0 siteuser@server:~/sitename.org/web$ wp option set siteurl https://sitename.org |
| | 23 | }}} |
| | 24 | |
| | 25 | |
| | 26 | The wp-cli utility can also [https://developer.wordpress.org/cli/commands/search-replace/ 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. |
| | 27 | |
| | 28 | 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. |
| | 29 | {{{ |
| | 30 | 0 siteuser@server:~/sitename.org/web$ wp search-replace --dry-run http://sitename.org https://sitename.org --skip-columns=guid |
| | 31 | }}} |
| | 32 | |
| | 33 | 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 |
| | 34 | |
| | 35 | {{{ |
| | 36 | 0 siteuser@server:~/sitename.org/web$ wp search-replace --dry-run http://www.sitename.org https://sitename.org --skip-columns=guid |
| | 37 | }}} |
| | 38 | |
| | 39 | {{{ |
| | 40 | 0 siteuser@server:~/sitename.org/web$ wp search-replace --dry-run http://oldsitename.org https://sitename.org --skip-columns=guid |
| | 41 | }}} |
| | 42 | |