Created
January 16, 2024 13:27
-
-
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.
This file contains hidden or 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
<?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