問題描述

長時間的潛行者 – 第一次海報。

我的客戶有一個 CakePHP 開發的網站,一個安裝在/blog /目錄下的 wordpress 部落格。

我們來說主域名是 http://www.realdomain.com,部落格是 http://www.realdomain.com/blog/

他們沒有自己的 SSL 證書,所以他們使用我的公司。假設安全網址是 https://realdomain.maindomain.net/blog/

我的 wp-config.php 檔案中有以下程式碼:

define('WP_SITEURL', 'https://realdomain.maindomain.net/blog');
define('WP_CONTENT_URL', 'http://www.realdomain.com/blog/wp-content');
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);

當我去/wp-login.php,它將我重定向到完美的安全網址。

但是,當我登入到安全網站時,WordPress 會嘗試從中載入 JavaScript 和樣式

`http**s**://realdomain.com`

這導致問題,因為主站點沒有 SSL 證書,因此不會從 https://realdomain.com 載入任何內容

還有什麼我失蹤的嗎?

解決方案是.htaccess 規則?將所有 「https://realdomain.com」 路由到"https://realdomain.maindomain.com 的規則 「?

我會支付任何人誰可以幫助我修復它 20 美元。 I’ve Google’D 直到我的心內容,我不知道還能做什麼。

非常感謝!

最佳解決方法

只是為了保持好東西清楚的是,我已經發布了這個新的答案。讓我們重新設定遊戲場& 請遵循以下說明,就好像它是一個閃亮的新安裝 (忽略以前的答案中的所有程式碼和建議) 。

在您的 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 );

?>

我建議使用 Must-Use 外掛 (mu-plugins),因為它們是自動載入的,而不必首先被啟用。

如果您希望它是標準外掛,則需要在啟用後新增 FORCE_SSL_*常量。

次佳解決方法

我把我的頭撞在牆上,試圖將 wordpress 上的管理功能移到單獨的伺服器上。我以為我只是補充說,有兩個主機名在編輯器中打破了”preview” 功能,所以你需要修改你的.htaccess,使它再次工作。

#special fixes on previews when wordpress sends user to the public blog & we want the hidden one.
RewriteCond %{HTTP_HOST} ^public.site.com$ [NC]
RewriteCond %{QUERY_STRING} .*(/?preview=true.*) [OR]
RewriteCond %{QUERY_STRING} (.*&preview=true.*) [NC]
RewriteRule ^(.*)$ http://secure.site.com/$1$2  [L,R=301]

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。