Change WordPress Permalink Without Losing Traffic

Posted in: Programming,Website & Blog |

This post is also available in: Indonesian

permalink

When we change the structure of the Permanent Link (Permalink) address in WordPress, old URL address of blog posts will also be changed with the new permalink and will not be accessible anymore using the old URL address. If those blog posts already crawled by search engines such as Google, Yahoo, etc. or the posts’ URL are mentioned in other webs, eg on Twitter or Facebook, because the changing of permalink, we can lose traffic to our blog. So what can we do to keep the traffic, especially for posts with most frequent visit? The way how to fix this is by installing WordPress plugin Permalinks Moved Permanently.

This plugin outsmart a way by redirecting the old URL address to a new URL address based on post slug information. So if the same slug is found, before the old permalink generate 404 error message because the old URL is not found, it will produce the message “301 Moved Permanently” and redirect to the new URL address.

For example: the old adress from by blog post:

http://www.hikaruyuuki.com/blog/2008/11/14/boneka-boneka-jepang-bagian-1.phpx

because I changed the permalink, when someone click on address above, then it will be redirected to the new address

http://www.hikaruyuuki.com/blog/boneka-boneka-jepang-bagian-1.html


However, there is one problem arised and made this plugin does not work correctly, my hypothesis is because the slug is taken from URL basename and the extension changed from .phpx to .html, resulted slug from URL basename will be different from slug in database. So the trick is by removing the extension from URL before passed to the function in plugin to generate the slug. To do so, edit the file, permalinks-moved-permanently.php in line 44 as follow.

$slug = ShowFileName( $_SERVER['REQUEST_URI']);

and add function below in the end of file:

function ShowFileName($filepath)
{
   preg_match('/[^?]*/', $filepath, $matches);
   $string = $matches[0];
   #split the string by the literal dot in the filename
   $pattern = preg_split('/./', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
   #get the last dot position
   $lastdot = $pattern[count($pattern)-1][1];
   #now extract the filename using the basename function
   $filename = basename(substr($string, 0, $lastdot-1));
   #return the filename part
   return $filename;
}

Finally, after I save the file, the old Permalink sucessfully redirected to the new Permalink.

Related Posts




Speak Up!

Leave your own comment

Notify me of follow-up comments via e-mail (or subscribe here).

Notify me of follow-up comments via e-mail (or subscribe here).




 

Share

Subscribe Feed

Email

Facebook

Twitter

Delicious

Digg

StumbleUpon

Google Buzz

Deviantart