Wordpress: Redirecting Old Tag URL to New Tag Location
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.
E-mail this to a Friend
Printable Version
You may also be interested in other helpful articles:
- Wordpress 2.5 Released
- Upgrade wordpress quickly in 3 easy steps from UNIX shell prompt
- Download of The Day: WordPress 2.6
- WordPress 2.0.5 (Ronan) available for download
- Download of the day: WordPress 2.0.6
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: error 301, error 404, Linux, new location, php code, php str_replace(), wordpress, wordpress tag




A WordPress plugin that replies a 301 permanent redirect, if requested URI is different from entry’s (or archive’s) permalink. It is used to ensure that there is only one URL associated with each blog entry.
Nice info… bookmarked - just incase I think of changing URL structure