{"id":1542,"date":"2003-07-31T14:06:12","date_gmt":"2003-08-01T04:06:12","guid":{"rendered":"http:\/\/michaelhans.com\/eclecticism\/2003\/07\/31\/help-wanted-apachephp\/"},"modified":"2019-12-05T13:30:07","modified_gmt":"2019-12-05T21:30:07","slug":"help-wanted-apachephp","status":"publish","type":"post","link":"https:\/\/michaelhans.com\/eclecticism\/2003\/07\/31\/help-wanted-apachephp\/","title":{"rendered":"Help wanted: Apache\/PHP"},"content":{"rendered":"<p>I&#8217;m planning on sticking with TypePad as my weblog host once everything opens up officially (<a href=\"http:\/\/www.sixapart.com\/log\/2003\/07\/5_days_of_typep.shtml\" title=\"5 Days of TypePad\">tomorrow<\/a>, from the looks of it). However, this poses a bit of a problem. While I&#8217;m slowly moving all of my old posts from my old weblog to this new site, there are still lots of links scattered throughout the &#8216;net that point to the old addresses.<\/p>\n<p>I think I know of a solution, however, I&#8217;m not well enough versed in the intricacies of Apache and PHP to pull it off on my own. So, I&#8217;m asking for help!<\/p>\n<p>Here&#8217;s what I&#8217;d like to do&#8230;<\/p>\n<p>All of my old posts reside at my personal server at <a href=\"http:\/\/www.djwudi.com\/longletter\/\">http:\/\/www.djwudi.com\/longletter\/<\/a>. It&#8217;s a Mac OS X computer running Apache, with PHP enabled.<\/p>\n<p>I know that Apache can handle redirects, based on rules set up in the httpd.conf file. I also know that pattern matching and text string munging can be carried out in PHP.<\/p>\n<p>All of my old individual entry pages are stored in my webserver with the following directory structure:<\/p>\n<p>http:\/\/www.djwudi.com\/longletter\/archives\/<strong>year\/month\/day\/dirified&#95;post&#95;title.php<\/strong> http:\/\/www.djwudi.com\/longletter\/archives\/<strong>2003\/07\/31\/help&#95;wanted&#95;apache&#95;php.php<\/strong><\/p>\n<p>All of the pages on this new site are stored using a similar, but slightly different directory structure:<\/p>\n<p>http:\/\/djwudi.typepad.com\/eclecticism\/<strong>year\/month\/truncated&#95;title.html<\/strong> http:\/\/djwudi.typepad.com\/eclecticism\/<strong>2003\/07\/help&#95;wanted&#95;apa.html<\/strong><\/p>\n<p>What I&#8217;m envisioning for the final system is this:<\/p>\n<ul>\n<li>Anytime my webserver receives a request for a page that resides within the &#8216;\/longletter\/archives\/&#8217; directory, Apache redirects to a customised PHP script on my server.<\/li>\n<li>That script does three things:\n<ol>\n<li>Presents a simple page to the user with wording to the effect of &#8220;This site has moved, one moment while we redirect you&#8230;&#8221;.<\/li>\n<li>Looks at the requested URI and converts it to what the new URI should be. As I&#8217;ve kept post titles consistent, and the directory structures are similar, this should be fairly easy with the right regular expressions.\n<ol>\n<li>Parse the requested URI.<\/li>\n<li>Remove everything before the 4-digit year and replace it with the new base address.<\/li>\n<li>Remove the 2-digit day.<\/li>\n<li>Truncate the post title to fifteen characters.<\/li>\n<li>Remove the .php extention and replace it with .html.<\/li>\n<\/ol>\n<\/li>\n<li>Redirects the users browser to the new, correct URI.<\/li>\n<\/ol>\n<\/li>\n<li>Hey presto, we&#8217;re done &#8212; no matter which page was linked to at my old site, the user has been redirected to the corresponding page at my new site.<\/li>\n<\/ul>\n<p>More brainstorming:<\/p>\n<ul>\n<li>The above method works well for links going to individual pages, but what about category archives or the main index page itself?<\/li>\n<li>Could the PHP script be made smarter? For instance&#8230;\n<ol>\n<li>If the requested URI contains the year\/month\/day\/title.php string, then the above transformation and redirect is processed.<\/li>\n<li>If the requested URI contains any other string (in other words, it doesn&#8217;t point to a specific post), then a page is presented that says something along the lines of &#8220;This site has moved, one moment while we redirect you to the new site&#8230;&#8221;, and a redirect is passed to the user&#8217;s browser that points to the index page of the new weblog.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>Anyway, that&#8217;s what I&#8217;d like to do. It all seems straightforward enough in my brain, and I think that the technology I have available should be able to handle it all without a problem &#8212; I just don&#8217;t have the <em>faintest<\/em> idea how to code it.<\/p>\n<p>Any and all advice, hints, tips, or straight-up solutions would be <em>greatly<\/em> appreciated. I&#8217;m not rich enough to offer untold wealth or cool prizes or anything, but I can offer much gratitude, public thanks and kudos, and probably pizza and beer (or a PayPal donation to a &#8216;pizza and beer&#8217; fund, or some such thing).<\/p>\n<p>And you won&#8217;t even have to fight me for the beer &#8212; I can&#8217;t stand the stuff. ;)<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:13916,&quot;href&quot;:&quot;http:\\\/\\\/www.sixapart.com\\\/log\\\/2003\\\/07\\\/5_days_of_typep.shtml&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;https:\\\/\\\/movabletype.com&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:13240,&quot;href&quot;:&quot;http:\\\/\\\/www.djwudi.com\\\/longletter&quot;,&quot;archived_href&quot;:&quot;https:\\\/\\\/web-wp.archive.org\\\/web\\\/20050403220727\\\/http:\\\/\\\/www.djwudi.com:80\\\/longletter\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-03-12 08:30:12&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-03-18 19:59:18&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-03-27 06:16:41&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-04-05 13:48:12&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-04-08 17:26:12&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-04-15 19:40:34&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-04-26 10:33:02&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-04-30 06:42:09&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-05-07 14:17:33&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-05-10 20:21:28&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-05-14 04:26:49&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-05-19 13:30:12&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-09 09:14:18&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-06-17 13:30:25&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-06-26 05:26:41&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-07-10 19:26:48&quot;,&quot;http_code&quot;:500},{&quot;date&quot;:&quot;2026-07-17 06:17:33&quot;,&quot;http_code&quot;:500}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-17 06:17:33&quot;,&quot;http_code&quot;:500},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m planning on sticking with TypePad as my weblog host, however, this poses a bit of a problem with broken links. Can any Apache\/PHP gurus help me?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2040],"tags":[65],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-blog","tag-technology"],"_links":{"self":[{"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/comments?post=1542"}],"version-history":[{"count":0,"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"wp:attachment":[{"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelhans.com\/eclecticism\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}