How to move Magento 2 root URL to another domain

To move Magento 2 root URL to another domain, you have to perform a procedure that is similar to one available in Magento 1.x. Note that Magento 2 has the similar to Magento 1 stores shop root URL available in the core_config_data database table. Furthermore, record paths are the same: web/unsecure/base_url and web/secure/base_url. Consequently, you it is possible to change root URL by SQL query:
 
                
			
			
		| 1 2 3 | UPDATE core_config_data  SET value = 'http://example.ru/'  WHERE path IN ('web/secure/base_url', 'web/unsecure/base_url'); | 
It is enough for Magento 1, but Magento 2 stores root URL in the third path: design/head/includes
As a result, the record looks as follows:
| 1 | <link  rel="stylesheet" type="text/css"  media="all" href="<root URL>/pub/media/styles.css" /> | 
Therefore, there is a necessity to utilaze an additional SQL query:
| 1 2 3 | UPDATE core_config_data SET value = REPLACE(value, '<old root URL or domain>', '<new root URL or domain>') WHERE path = 'design/head/includes'; | 
Check the following example:
| 1 2 3 | UPDATE core_config_data SET value = REPLACE(value, 'http://old.com/', 'http://new.com/') WHERE path = 'design/head/includes'; | 
Don’t forget to clear cache:
| 1 | rm -rf var/cache/* | 
More tips from Magento 2 cookbook
 
                
								
			

 
            




