Skip to content

Instantly share code, notes, and snippets.

@gmcmillan
Last active July 11, 2019 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmcmillan/88680c4ad62b5861fe4a to your computer and use it in GitHub Desktop.
Save gmcmillan/88680c4ad62b5861fe4a to your computer and use it in GitHub Desktop.
use a different domain for wp-admin, from this stack exchange post: http://wordpress.stackexchange.com/a/39210/81906
<?php
// this goes in wp-content/mu-plugins/ssl-domain-alias.php
/**
* Plugin Name: SSL Domain Alias
* Plugin URI: http://wordpress.stackexchange.com/questions/38902
* Description: Use a different domain for serving your website over SSL, set with <code>SSL_DOMAIN_ALIAS</code> in your <code>wp-config.php</code>.
* Author: TheDeadMedic
* Author URI: http://wordpress.stackexchange.com/users/1685/thedeadmedic
*
* @package SSL_Domain_Alias
*/
/**
* Swap out the current site domain with {@see SSL_DOMAIN_ALIAS} if the
* protocol is HTTPS.
*
* This function is not bulletproof, and expects both {@see WP_SITEURL} and
* {@see SSL_DOMAIN_ALIAS} to be defined.
*
* @todo The replacement is a simple string replacement (for speed). If the
* domain name is matching other parts of the URL other than the host, we'll
* need to switch to a more rigid regex.
*
* @param string $url
* @return string
*/
function _use_ssl_domain_alias_for_https( $url )
{
static $domain;
if ( ! isset( $domain ) )
$domain = defined( 'WP_SITEURL' ) && defined( 'SSL_DOMAIN_ALIAS' ) ? parse_url( WP_SITEURL, PHP_URL_HOST ) : false;
if ( $domain && strpos( $url, 'https' ) === 0 )
$url = str_replace( $domain, SSL_DOMAIN_ALIAS, $url );
return $url;
}
add_filter( 'plugins_url', '_use_ssl_domain_alias_for_https', 1 );
add_filter( 'content_url', '_use_ssl_domain_alias_for_https', 1 );
add_filter( 'site_url', '_use_ssl_domain_alias_for_https', 1 );
?>
define( 'WP_SITEURL', 'http://www.realdomain.com/blog' );
define( 'SSL_DOMAIN_ALIAS', 'realdomain.maindomain.net' );
define( 'FORCE_SSL_LOGIN', true );
define( 'FORCE_SSL_ADMIN', true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment