Skip to content

Instantly share code, notes, and snippets.

@jacks0n
Created May 15, 2014 05:42
Show Gist options
  • Save jacks0n/7b16684636532c6c92a0 to your computer and use it in GitHub Desktop.
Save jacks0n/7b16684636532c6c92a0 to your computer and use it in GitHub Desktop.
WordPress Any URL - A quick and dirty way of allowing WordPress to run on any URL, without having to replace URLs in the database. It will figure out the home URL, based on the current hostname and relative path from the server's root directory. It will also re-write existing links with the current site, using output buffering. eg. http://oldser…
// Add whatever URLs you want to replace with the current home URL
$replace_urls = array('http://exampleoldsite.com/mysite');
$uri = str_replace("{$_SERVER['DOCUMENT_ROOT']}/", '', dirname(__FILE__));
$home_url = sprintf('%s://%s/%s', $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http', $_SERVER['SERVER_NAME'], $uri);
define('WP_SITEURL', $home_url); define('WP_HOME', $home_url);
function replace_old_urls($html) { global $replace_urls; return str_replace($replace_urls, WP_SITEURL, $html); }
ob_start('replace_old_urls');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment