WordPress: Redirecting Old Tag URL to New Tag Location

Posted on in Categories Howto, lighttpd, Linux, php last updated October 8, 2008

Recently, I had noticed lots of 404 error generated by my wordpress software. My old wordpress tag structure changed from:
/tips/tag/linux_software
/tips/tag/one_two_foo

To:
/tips/tag/linux-software
/tips/tag/one-two-foo

As a result lots of error 404 was dumped into my log file. I wrote a small php code to get rid of the problem:

My tag301.php:

<?php
$newTagUrl='http://www.cyberciti.biz/tips/tag/'.str_replace('_', '-', $_GET['r']);
@include_once("../include.genlib.php");
movePage(301, $newTagUrl);
?>

Finally, I updated my mod_rewrite (lighttpd rewrite engine) to redirect to new location:

 "^/tips/tag/(.*_.*)+$" => "/tag301.php?r=$1"

Code for movePage() is here.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

2 comment

Leave a Comment