Created
March 3, 2021 16:19
-
-
Save KamGraphica/c30e91445ce2077c03128541db619270 to your computer and use it in GitHub Desktop.
Custom wp-config for wordpress behind reverse proxy & using a staging server
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
/* Staging and reverse proxy settings */ | |
$public_url = 'https://public-server.com'; | |
$production_server = 'production.example.com'; | |
$staging_server = 'stage.example.com'; | |
/* Staging and reverse proxy code */ | |
if($_SERVER['REQUEST_URI'] == "/?cookiesetter"){ | |
setcookie("admincookie", 'exists', time()+3600*6, '/', $production_server, true, true); /* expire in 6 hours */ | |
header("Location: https://$production_server/wp-admin/", TRUE, 302); | |
exit; | |
} | |
if($_SERVER['REQUEST_URI'] == "/?cookieremover"){ | |
setcookie("admincookie", '', time()-3600, '/', $production_server, true, true); /* expired, removes cookie */ | |
header("Location: /", TRUE, 302); | |
exit; | |
} | |
if($_SERVER['HTTP_HOST'] == 'staging_server'){ | |
define( 'WP_SITEURL', "https://$staging_server" ); | |
define( 'WP_HOME', "https://$staging_server" ); | |
header("X-Robots-Tag: noindex, nofollow", true); | |
} | |
if($_SERVER['HTTP_HOST'] != $staging_server ){ | |
if(isset($_COOKIE['admincookie'])){ | |
define( 'WP_SITEURL', "https://$production_server" ); | |
define( 'WP_HOME', "https://$production_server" ); | |
} else { | |
define( 'WP_SITEURL', "https://$production_server" ); | |
define( 'WP_HOME', $public_url ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment