Created
May 15, 2014 05:42
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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