只是为了让事情保持美好&;很清楚,我已经发布了一个新的答案。让我们重新设置比赛场地&;按照以下说明进行操作,就像它是一个全新的安装一样(忽略前面答案中的所有代码和建议)。
在您的wp-config.php
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 );
并且在
wp-content/mu-plugins/ssl-domain-alias.php
<?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 );
?>
我建议使用必用插件(
mu-插件),因为这些插件是自动加载的,无需首先激活。
如果您希望它是一个标准插件,则需要添加FORCE_SSL_*
激活后的常数。