{"id":369,"date":"2011-07-17T23:50:57","date_gmt":"2011-07-18T06:50:57","guid":{"rendered":"http:\/\/10.0.1.201\/?p=369"},"modified":"2011-07-17T23:50:57","modified_gmt":"2011-07-18T06:50:57","slug":"redirect-old-uris-to-new-wordpress-posts-using-php","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2011\/07\/17\/redirect-old-uris-to-new-wordpress-posts-using-php\/","title":{"rendered":"Redirect old URI&#8217;s to new WordPress posts using PHP"},"content":{"rendered":"<p>In my case I migrated from a custom blog to WordPress. My old one used a GET string in the URL to define which post to load and now I&#8217;d like to redirect one and maybe others to their WordPress counterparts.<br \/>\n<!--more--><br \/>\nUsing %{QUERY_STRING} in some mod_rewrite mojo might get the job done, but a) mod_rewrite makes my brain melt and b) There is zero reason the server should compare every request looking for something going to the WordPress index page alone.<\/p>\n<p>This will need to be placed at the top of the index.php file used by WordPress. The &#8220;301&#8221; at the end of the <em>header()<\/em> function is the HTTP status &#8220;moved permanently&#8221;. This example is unique to this site but you should be able to define your own from it if you have a similar need.<\/p>\n<p><code>if ($_GET['focus']) {<br \/>\n\tswitch ($_GET['focus']):<\/p>\n<p>\t\tcase \"34\":<br \/>\n\t\t$new_loc = \"\/2007\/10\/itunes-library-to-mysql-database\/\";<br \/>\n\t\tbreak;<\/p>\n<p>\tendswitch;<br \/>\n\theader(\"Location:http:\/\/\".$_SERVER['SERVER_NAME'].$new_loc,301);<br \/>\n\texit;<br \/>\n}<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my case I migrated from a custom blog to WordPress. My old one used a GET string in the URL to define which post to load and now I&#8217;d like to redirect one and maybe others to their WordPress counterparts.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,7],"tags":[15,30],"class_list":["post-369","post","type-post","status-publish","format-standard","hentry","category-code","category-web","tag-fixit","tag-php"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}