Consolidating several blogs into a single multisite instance - we have 2 sets of blogs - active and archived.

What's the best way of adding /archive/ to the URLs of the archived blogs?

So, as an example:

  • An active blog would be accessed via www.domain.com/blogname
  • An archived blog would be accessed via www.domain.com/archived/blogname

I've taken a look at a couple of domain mapping plugins (including the WPMU Dev) one, but I don't think they do what I need.

1 Answer 1


In order to do partition your blogs like this you're going to need to write a custom plugin similar to the WordPress MU Domain Mapping plugin. Here's how your plugin needs to work.

  1. Create a sunrise.php file for your plugin, and properly define('SUNRISE',true); in your wp-config.php file.
  2. Create a table which maps the tuples {blog_slug, blog_id, is_archived}

In sunrise.php perform the following logic:

$access_url = $_SERVER[ 'REQUEST_URI' ];
$on_archive = false;
$slug = "";
$parts = explode('/',$access_url);
for($i = 0; $i < count($parts); ++$i) {
   if(strpos($parts[i],"yourdomain.com") !== false) {
      if($parts[i + 1] == "archived") {
         $on_archive = true;
         $slug = $parts[i+2]; // TODO: Index checking
      } else
         $slug = $parts[i + 1];

$blog_id = $wpdb->get_var("SELECT blog_id FROM YOURTABLE WHERE blog_name=$slug ...");
if($blog_id && $on_archive) {
   $current_blog = $wpdb->get_row("SELECT * FROM {$wpdb->blogs} WHERE blog_id = '$blog_id' LIMIT 1");
   $current_blog->path = '/archived';
   $site_id = $current_blog->site_id;

   $current_site = $wpdb->get_row( "SELECT * from {$wpdb->site} WHERE id = '{$current_blog->site_id}' LIMIT 0,1" );
   $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
} else {
   // Things went wrong, redirect to the home page, or something

Finally, populate the fields of your table so that it knows which blogs are "archived". In production you'd probably want to add some array safety checks, as well as checking that if "blog_a" is archived, then visiting yourdomain.com/blog_a redirects to yourdomain.com/archived/blog_a. All of these things can be handled in the sunrise file.

  • thanks - i'll be able to test this later today or tomorrow and give some feedback
    – anu
    Commented Apr 27, 2011 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.