Skip to content

Instantly share code, notes, and snippets.

@razaanstha
Created January 16, 2024 13:27
Show Gist options
  • Save razaanstha/89899d6b4f89718f93492fb5cd9605f6 to your computer and use it in GitHub Desktop.
Save razaanstha/89899d6b4f89718f93492fb5cd9605f6 to your computer and use it in GitHub Desktop.
Redirect all of your local WP site medias to remote site; saving local storage and media migration hassle.
<?php
$remote_site = 'https://' . basename(dirname(__FILE__)) . '.com';
// Comment the line above and uncomment the following line if your local site url is not based on directory
// $remote_site = 'https://www.your-remote-site.com';
if (!empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['REQUEST_URI']) && preg_match('/^\/wp-content\/uploads\/(.*)$/', $_SERVER['REQUEST_URI'], $matches) && !file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI'])) {
header('Location: ' . $remote_site . '/wp-content/uploads/' . $matches[1]);
exit;
}
// Your exisitng wp-config.php config goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment