How LibDemHome was created

So this morning LibDemVoice announce that it had been bought out by Lord Ashcroft as was renamed LibDemHome.

Of course being announce in the morning of the 1st April it was just an April Fools joke. One first conceived over two years ago, and started three months ago, but to ensure that everything went smoothly (and that I didn’t have to flick a switch whilst asleep) here are the steps used to have a new domain name, different theme and redirects.

The Domain
Some webhosting companies will allow you to park a domain at your site. What this results in is that anyone visiting domain2.com gets the content on domain1.com. Ours does this for no extra cost (but other may).
We already have parking for .org.uk, .com, .co.uk and .net variations of LibDemVoice.

.htaccess
In our .htaccess file we already have code

# Redirect all other domain names to main home page
RewriteCond %{HTTP_HOST} ^(www\.)?ldv\.org\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?libdemvoice\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?libdemvoice\.net$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?libdemvoice\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?libdemvoice\.org\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^libdemvoice\.org$
RewriteRule ^(.*)$ http://www.libdemvoice.org/$1 [R=301,L]

which translated says, if you access the site via any other the other urls with or without the www or if you try libdemvoice.org without the www redirect to www.libdemvoice.org

Now I needed something which said on April 1st redirect to libdemhome and hoped that .htaccess would have some time/date conditions so that I wouldn’t have to edit the file before and after. Turns out after a bit of googling that indeed it does, so here is what we have right at the top

RewriteCond %{HTTP_HOST} ^(www\.)?libdemvoice\.org$
RewriteCond %{TIME_MON} =04
RewriteCond %{TIME_DAY} =01
RewriteCond %{TIME_HOUR} >1
RewriteCond %{TIME_HOUR} <12 RewriteRule ^(.*)$ http://www.libdemhome.org/$1 [R=302,L]

In "English" if the URL is libdemvoice.org (with or without the Ws), and it's the 4th Month of the year, and the Day is the 1st, and the Hour is past 1, and the Hour is before 12, redirect to www.libdemhome.org taking all the stuff after the domain with you, but telling computers that this redirection is only a temporary one (R=302).

The Theme
I took the theme LibDemVoice already had and created a copy of the theme directory with a new name. I then slightly tweaked the CSS file to change some of the colours and fonts, and GIMPed the logo from Conservative Home. Uploaded this to the site and left it there.

The Pluging
Next I needed a way to see how the site looked whilst testing, I had a theme preview plugin which I had used in the past, but needing to solve the issue of making sure it was this theme on the 1st I created my own plugin for this purpose.

<?php
/*
* Plugin Name: LDHome Theme Activator
* Plugin URI: https://blog.artesea.co.uk
* Description: Changes the theme to LDHome when at www.libdemhome.org
* Author: Ryan Cullen
* Author URI: https://blog.artesea.co.uk
* Version: 0.1
*/

function use_ldhome_theme($x) {
return 'ldhome';
}
function use_ldhome_url($x) {
return str_replace('http://www.libdemvoice.org', 'http://www.libdemhome.org', $x);
}
function use_ldhome_name($x) {
return 'Liberal Democrat Home';
}

if(strpos($_SERVER['HTTP_HOST'], 'libdemhome') !== FALSE) {
add_filter('template', 'use_ldhome_theme');
add_filter('stylesheet', 'use_ldhome_theme');
add_filter('option_blogname', 'use_ldhome_name');
remove_action('wp_head', 'rel_canonical');
if(date("ymdHi") < 1104011200) { add_filter('option_siteurl', 'use_ldhome_url'); add_filter('option_contenturl', 'use_ldhome_url'); add_filter('option_home', 'use_ldhome_url'); } } ?>

The translation is if the domain which the script was loaded from includes libdemhome, then override the current theme to my new one called ldhome, set the site name to Liberal Democrat Home and whilst it's before midday replace any links which have www.libdemvoice.org in them with www.libdemhome.org (it also has a line to remove the rel="canonical" from the header).
The advantage of these rules meant that I didn't need to go through the theme looking for lines which used the site name functions and replace them all with Liberal Democrat Home, and by having the links point to libdemhome it was one less redirection on the server. (Although the reason for setting the links back after midday way to send traffic back to the original URL).

With these small bits of code the site change all went to plan, and a scheduled post from Ashcroft finished it off whilst I slept, and then at midday I was able to continue my day job without have to find a moment to play about with the server to turn it all off.

The domain is still live, and it still shows the alternate theme if you fancy taking a look.

Leave a Reply

Your email address will not be published. Required fields are marked *

Human test: Enter Ryan backwards