{"id":15,"date":"2006-10-27T11:52:15","date_gmt":"2006-10-27T15:52:15","guid":{"rendered":"http:\/\/whoisgregg.com\/blog\/2006\/10\/wordpress-mod_rewrite-still-allows-old-url-string.html"},"modified":"2006-10-27T11:58:12","modified_gmt":"2006-10-27T15:58:12","slug":"wordpress-mod_rewrite-still-allows-old-url-string","status":"publish","type":"post","link":"http:\/\/www.whoisgregg.com\/blog\/2006\/10\/wordpress-mod_rewrite-still-allows-old-url-string\/","title":{"rendered":"WordPress mod_rewrite still allows old URL string"},"content":{"rendered":"<p>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.<\/p>\n<p>`\/blog\/?p=123`<\/p>\n<p>The &#8220;quick fix&#8221; for this is a few lines of code added to the top of the &#8220;single.php&#8221; file in your wordpress template:<\/p>\n<p>`<br \/>\n<?php\nif(preg_match(\"\/p=[0-9]+\/\", $_SERVER['QUERY_STRING'])){\n\theader(\"HTTP\/1.1 301 Moved Permanently\");\n\theader(\"Location: \".get_permalink());\n}\n?><br \/>\n`<\/p>\n<p>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. :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,5,8],"tags":[],"_links":{"self":[{"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/posts\/15"}],"collection":[{"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.whoisgregg.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}