{"id":4571,"date":"2018-04-04T08:54:04","date_gmt":"2018-04-04T06:54:04","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=4571"},"modified":"2020-02-09T11:24:40","modified_gmt":"2020-02-09T10:24:40","slug":"wordpress-change-url","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/wordpress-change-url-4571\/","title":{"rendered":"Change URL of a WordPress website"},"content":{"rendered":"<p>To change the URL of a WordPress site \u2013 for example, when a completely different domain should be used or to change from <code class=\"lang-bash\">http:\/\/<\/code> to <code class=\"lang-bash\">https:\/\/<\/code> \u2013 there are various solutions. This post describes two of them.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Important info before starting<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The new domain should already point to the folder of the installation, so you can access it after making the change. <strong>Otherwise, you will not be able to access your website after changing the URL<\/strong> (except it was only a protocol change, then you will get a safety warning from your browser if you do not have a valid SSL certificate).<\/li><li>Create a backup, just for safety\u2019s sake.<\/li><li>Do not modify the guid column in the database (<a href=\"https:\/\/codex.wordpress.org\/Changing_The_Site_URL#Important_GUID_Note\">that would lead to old articles being marked as new in feedreaders<\/a>).<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Modifying the URL with a plugin<\/h2>\n\n\n\n<p>There are different plugins that let you change the URL in the database. I like to use <a href=\"https:\/\/de.wordpress.org\/plugins\/better-search-replace\/\"><em>Better Search Replace<\/em><\/a>. After installing it, you will find the new menu item <em>Tools<\/em> \u203a <em>Better Search Replace<\/em>. There you can specify what string to replace with what \u2013 the following screenshot shows that for the change of my .de domain to the .com domain.<\/p>\n\n\n\n<figure class=\"wp-block-image alignnone size-full wp-image-4572\"><noscript><img decoding=\"async\" width=\"998\" height=\"806\" src=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace.png\" alt class=\"wp-image-4572\" srcset=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace.png 998w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-248x200.png 248w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-300x242.png 300w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-768x620.png 768w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-806x651.png 806w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-600x485.png 600w\" sizes=\"(max-width: 998px) 100vw, 998px\"><\/noscript><img decoding=\"async\" width=\"998\" height=\"806\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20998%20806%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-4572 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20998%20806%22%3E%3C%2Fsvg%3E 998w\" sizes=\"(max-width: 998px) 100vw, 998px\" data-srcset=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace.png 998w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-248x200.png 248w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-300x242.png 300w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-768x620.png 768w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-806x651.png 806w, https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace-600x485.png 600w\" data-src=\"https:\/\/florianbrinkmann.com\/en\/wp-content\/uploads\/sites\/11\/2018\/04\/wordpress-change-site-url-better-search-replace.png\"><figcaption>The URL of a WordPress site can be changed using the Better Search Replace plugin fairly easy. (Screenshot: own installation)<\/figcaption><\/figure>\n\n\n\n<p>Under <em>Select Tables<\/em>, you can define the tables where the domain should be searched and replaced \u2013 generally speaking, you should select all here. By default, the <em>Run as dry run?<\/em> option is enabled, so you can see how many occurrences would be replaced by the plugin without really changing something. If the result of the dry run looks good, uncheck the option and restart the search and replace.<\/p>\n\n\n\n<p>After that, you should have finished the domain change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Changing the URL with WP-CLI<\/h2>\n\n\n\n<p>If you have installed WP-CLI on your server, you do not need an extra plugin but can use the <a href=\"https:\/\/developer.wordpress.org\/cli\/commands\/search-replace\/\"><code class=\"lang-bash\">wp search-replace<\/code> command<\/a>. If you are in the installation directory on the command line, that could look like this:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">wp search-replace https:\/\/florianbrinkmann.de https:\/\/florianbrinkmann.com --skip-columns=guid<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To make a dry run, add the <code class=\"lang-bash\">--dry-run<\/code> option to the call:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">wp search-replace https:\/\/florianbrinkmann.de https:\/\/florianbrinkmann.com --skip-columns=guid --dry-run<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And if you would like to modify all tables of a multisite installation, use the <code class=\"lang-bash\">--network<\/code> option:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">wp search-replace https:\/\/florianbrinkmann.de https:\/\/florianbrinkmann.com --skip-columns=guid --network<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">If you accidentally changed the domain to something wrong<\/h2>\n\n\n\n<p>If you made a mistake while changing the URL, you are likely not able to get into the backend to correct the mistake. In that case, you need SFTP access to your server and can reset the domain with the following to lines in the <code class=\"lang-markup\">wp-config.php<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code lang-php\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">define( <span class=\"hljs-string\">'WP_HOME'<\/span>, <span class=\"hljs-string\">'https:\/\/florianbrinkmann.de'<\/span> );\ndefine( <span class=\"hljs-string\">'WP_SITEURL'<\/span>, <span class=\"hljs-string\">'https:\/\/florianbrinkmann.de'<\/span> );<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>That is possible via the WP-CLI, too. Here you can directly update the option in the settings:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">wp option update home https:\/\/florianbrinkmann.de\nwp option update siteurl https:\/\/florianbrinkmann.de<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Or set the constants in <code class=\"lang-markup\">wp-config.php<\/code> (<code class=\"lang-bash\">--type=constant<\/code> is necessary to let the CLI create the entry if it does not exist):<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">wp config <span class=\"hljs-built_in\">set<\/span> WP_HOME https:\/\/florianbrinkmann.de --<span class=\"hljs-built_in\">type<\/span>=constant\nwp config <span class=\"hljs-built_in\">set<\/span> WP_SITEURL https:\/\/florianbrinkmann.de&nbsp;--<span class=\"hljs-built_in\">type<\/span>=constant<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After that, you should be able to get back into the backend. You see: it is also possible to change the domain with one of those three ways, or <em>Settings<\/em> \u203a <em>General<\/em>. But in these cases, the domain would not be replaced in the database (or at least not all occurrences, if you change it via the settings screen or <code class=\"lang-bash\">wp option update<\/code>). So in my opinion, the best solution is to use a plugin or the <code class=\"lang-bash\">wp search-replace<\/code> command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To change the URL of a WordPress site \u2013 for example, when a completely different domain should be used or to change from http:\/\/ to https:\/\/ \u2013 there are various solutions. This post describes two of them.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[37],"tags":[],"class_list":["post-4571","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"wp-worthy-pixel":{"ignored":false,"public":"16d5409154294ddcb7b060286496b613","server":"vg04.met.vgwort.de","url":"https:\/\/vg04.met.vgwort.de\/na\/16d5409154294ddcb7b060286496b613"},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=4571"}],"version-history":[{"count":5,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4571\/revisions"}],"predecessor-version":[{"id":5967,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/4571\/revisions\/5967"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=4571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=4571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=4571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}