Gregg Hilferding


Wordpress mod_rewrite Still Allows Old URL String

If you migrated a Wordpress blog from the old style URLs using the built-in permalink options, you may be surprised that all the old URLs are still accessible. This causes a problem with search engines which have already indexed those old URLs as they will look at the new URLs as duplicate content.

/blog/?p=123

The "quick fix" for this is a few lines of code added to the top of the "single.php" file in your wordpress template:

<?php if(preg_match("/p=[0-9]+/", $_SERVER['QUERY_STRING'])){ header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_permalink()); } ?>

I will be writing up a plugin to add this functionality in a more Wordpress friendly way, but for now a quick code change will work. :)

Published by Gregg Hilferding on October 27th, 2006 at 11:52 am. Filed under PHP, SEO, Webmaster1 Comment

No comments yet.

Leave a Reply