Archive for the ‘blogging’ Category

Moving WordPress from a sub-domain to a sub-path

Thursday, July 19th, 2018

Many years ago, it seemed a good idea to put the company blog to blog.itsth.com. Well, things have changed. SEO und https-certificates now make https://www.itsth.de/en/blog/ look better.

Here’s how to make the transition (assuming the data mentioned above):

  1. Add this to your .htaccess file:
    RewriteEngine on
    RewriteRule en/blog/(.*)$ /blog_rewrite.php?$1
  2. Create a file /blog_rewrite.php with this content:
    <?php
    
    function HandleAsRewrite($basepath, $blogurl)
    {
      $domain = strtolower($_SERVER['HTTP_HOST']); // "www.itsth.de"
      $scheme = strtolower($_SERVER['REQUEST_SCHEME']); // "https"
      $input = getenv("REQUEST_URI");
    
      if (substr($input, 0, strlen($basepath))==$basepath)
      {
        $page = file_get_contents($blogurl.substr($input, strlen($basepath)));
    
        $replacement = $scheme.'://'.$domain.$basepath;
        $page = str_replace($blogurl, $replacement, $page);
        $page = str_replace(str_replace('/', '\\/', $blogurl), str_replace('/', '\\/', $replacement), $page);
    
        foreach ($http_response_header as $headline)
          header ($headline);
    
        print $page;
    
        return(true);
      }
    
      return(false);
    }
    
    if (HandleAsRewrite('/en/blog/', 'http://blog.itsth.com/'))
      return;
    
    print "not found";
    
    ?>
  3. Optional: Edit the wordpress template’s header file and add:
    <link rel=”canonical” href=”https://www.itsth.de/en/blog<?php echo $_SERVER[‘REQUEST_URI’];?>”>

If you want to handle more than one blog, simply duplicate the “if (HandleAsRewrite” and the htaccess-entry.

Limitations: The script won’t handle POST data.

Tree development

Tuesday, March 23rd, 2010

No, not talking about trees in the terms of computer science this time. Real ones. This blog is taking part in my “a blog, a tree” project. Just by blogging about this and using this button, a tree gets planted for this blog:
My blog has planted a pine tree.

If you have a blog, you’re invited to take part, too. No cost for you, I’m paying the bill here. So, if you’re having a feeling that you should do something for the environment, join it and get your blog a tree: A blog, a tree

Running multiple WordPress blogs with one installation

Wednesday, August 20th, 2008

When trying to run this blog with the same installation as my “Outlook and Sync blog“, I found out that this was more difficult than expected. WordPress doesn’t have a readymade feature for this, you have to do some tricks. And most of the tricks that I found were pretty difficult or involved several steps.

Here’s a trick that is easier. It requires that:

  • The different blogs should be on different domains or subdomains
  • The blogs should take up the entire (sub)domain (so they shouldn’t start in a subfolder)

Then it’s quite easy. Simply configure all the blog’s domains to point to the same WordPress installation folder. You can probably do this in the configuration panel of your webspace provider.

Now edit the wp-config.php:

Before:

$table_prefix  = 'yourblog_';

After:

$domain  = $_SERVER['HTTP_HOST'];
if (stristr($domain, 'yourblogname1'))
�  $table_prefix  = 'yourblog1_';
else if (stristr($domain, 'yourblogname2'))
�  $table_prefix  = 'yourblog2_';
else
�  $table_prefix  = 'yourblog_';

As a nice side effect you’re only needing one database instance for this (they’re often limited in rented webspace) and just have more tables in the same database. All blogs use the same installed files, but have different content and can have different layouts and activated plugins.

Happy Blogging!