Migrating Old Permalinks to WordPress

December 30th, 2006

Now that I migrated to WordPress for blogging, the permalinks of my previous blog entries have changed.

For example:

/article_php_5_enterprise_edition_available_online

changed to:

/2006/11/26/article-php-5-enterprise-edition-available-online/

My initial idea was to use mod_rewrite by adding a RewriteRule for each old link redirecting to the new location, but that looked like a lot of copy&paste to me and would not teach me anything new.

Instead, I chose to redirect requests for old links to the WordPress search page. Try it out yourself: Click on this old permalink /article_php_5_enterprise_edition_available_online and you will be redirected to the search page, which displays the blog entry to you as a search result. This looks like a more flexible solution to me, just in case that my permalinks might change again one day.

The implementation was simple. I added a few lines of PHP code to the 404.php page of my WordPress theme as described in the support topic 404 Search Function for WordPress. I also added a header redirect directive.

This is the full code:

PHP:
  1. // Adjust if WordPress is located in subdirectory,
  2. // e.g. www.example.com/weblog. Otherwise leave empty.
  3. $blog_uri       = 'weblog';
  4.  
  5. // Don't change from here.
  6. $search_url     = $blog_uri.'/?s=';
  7. $search_term    = urldecode( substr($_SERVER['REQUEST_URI'],1) );
  8. $find           = array("'".$blog_uri."'", "'/'", "'[-/_]'") ;
  9. $replace        = " " ;
  10. $new_search     = preg_replace($find, $replace, $search_term);
  11. $new_search     = urlencode($new_search);
  12.  
  13. // Redirect to search page.
  14. header("Location: /".$search_url.$new_search."&http_status=404");

Notice that for security reasons, I use urlencode() for the search page URL to avoid HTTP Response Splitting.

Article "PHP 5 Enterprise Edition" available online

November 26th, 2006

I just found that my article entitled PHP 5 Enterprise Edition is now available online. It has initally been published in the
International PHP Magazine.

From the introduction:

Today, J2EE could be named the de facto industry standard for the development of distributed multi-tier architecture applications. It is backed up by industry leaders like Sun, Oracle, BEA, and IBM. This article will compare PHP's software stack with what's available in (and for) J2EE, to overcome the typical Java versus PHP discussions that usually focus on language features, but do not take into account the overall picture. Basically, this article assembles a PHP5 Enterprise Edition (PHP5EE).

Although this article is almost 3 years old, it is still very interesting to read. Especially when reading the following sentence or projection in the article's summary:

In no way should this article be a dispraise of all the good volunteer work that happens in the PHP community, but it definitely needs more successful companies in the PHP market who continuously climb up the ladder and extend the PHP software stack.

Considering that since the article has been published, two companies (eZ systems and Zend) have started to create their own libraries aka frameworks to extend the PHP software stack (eZ components and Zend Framework), I would say that PHP is on the right way and that my article was quite influential :)