Faced a task, there are 2 identical sites on wordpress , one database, the only difference is that the first site has access to the Internet, and the other is deployed locally, one domain www.example.ru another example.local, as in principle can I replace links if the local version does not have access to the Internet? I try this:

 function checkURL($url){ $domain = get_bloginfo('url'); $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); /* Get the HTML or whatever is linked in $url. */ $response = curl_exec($handle); /* Check for 404 (file not found). */ $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if($httpCode == 404) { $url = str_replace($domain, 'example.local', $url); return $url; /* Handle 404 here. */ } else { return $url; } curl_close($handle); wp_die(); } 

And I make this check for each link on the site, but the problem is that because of this the site loading time increases greatly, how can you solve it differently?

1 answer 1

Add the following lines to the local site in the wp-config.php :

 define( 'WP_HOME', 'http://example.local' ); define( 'WP_SITEURL', 'http://example.local' ); 
  • one
    This method works only on the most simple sites, without serialized data - KAGG Design