WordPress SSL small and easy hack

Hi people.
Just installed WordPress (version 2.0.10-1etch3). After the regular installation procedure, the first thing I was trying to do is to configure the SSL.
Being naive, just added Apache alias on another virtual host (which has SSL) to point to the same directory as the original installation.
Oops, that does not work. Googled. Came up with:
http://codex.wordpress.org/Administration_Over_SSL
That page just scared me. It looks too complicated for whatever it does. Spent few additional minutes of search. No satisfying answer.

Here is my small hack which works for me and which should work fine for any installations as long as URI beginnings are the same on both virtual hosts (read same Apache alias, that’s roughly the same thing)
In wp-config.php I’ve added at the end, just before ?> :

wp_cache_add('home_before_ilya', get_option('home'), 'options');
add_filter('option_siteurl', 'ilyas_siteurl');
add_filter('option_home', 'ilyas_siteurl');

function ilyas_siteurl($v) {
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $s = 's';
    } else {
        $s = '';
    }
    $v = "http$s://{$_SERVER['HTTP_HOST']}/blog";
    return $v;
}

In wp-includes/functions.php in function weblog_ping :
Replace

$home = trailingslashit( get_option('home') );

with

$home = trailingslashit( get_option('home_before_ilya') );

Note that the code was not really tested. All I know is it worked for me. Use at your own risk!
Hope that helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s