{"id":823,"date":"2006-11-15T11:23:00","date_gmt":"2006-11-15T09:23:00","guid":{"rendered":"http:\/\/www.mummila.net\/nuudelisoppa\/index.php\/?p=823"},"modified":"2006-11-15T11:23:00","modified_gmt":"2006-11-15T09:23:00","slug":"replacing-changed-directory-names-with-htaccess","status":"publish","type":"post","link":"https:\/\/mummila.net\/nuudelisoppa\/2006\/11\/15\/replacing-changed-directory-names-with-htaccess\/","title":{"rendered":"Replacing changed directory names with .htaccess"},"content":{"rendered":"<p>After poking around with some <a href=\"http:\/\/httpd.apache.org\/docs\/1.3\/mod\/mod_rewrite.html\">Rewrite rules<\/a> and nearly losing my nerve with what seemed to be a choice between a <code>500 Internal Error<\/code> and WordPress&#8217; 404 pages, I finally came up with a redirect instruction for my .htaccess file that replaces a subdirectory name in URLs which end in .html.<\/p>\n<p>I need this because when I started <a href=\"http:\/\/mummila.net\/marginaali\/\">marginaali<\/a>, I used <a href=\"http:\/\/www.blogger.com\/\">Blogger<\/a> which outputs html files. I then moved on to <a href=\"http:\/\/wordpress.org\/\">WordPress<\/a> and imported everything I had blogged thus far &#8211; apart from the comments that I had received. Therefore I didn&#8217;t have the heart to delete all those .html files and was sort of stuck between the two.<\/p>\n<p>After activating <a href=\"http:\/\/codex.wordpress.org\/Using_Permalinks#mod_rewrite_.28.22Pretty_Permalinks.22.29\">pretty permalinks<\/a>, all requests to those old posts were redirected to the WordPress ones, and so the comments were, in effect, not available. Not until I changed the old posts&#8217; directory name from both Blogger&#8217;s and WordPress&#8217; standard naming by the year, by prefixing the (thankfully only) 2004 directory with an &#8216;o&#8217;, into &#8216;o2004&#8217;.<\/p>\n<p>There was one additional problem: that of old links out there in the Net pointing to these old posts and the comments in them &#8211; they were now broken of course. Here&#8217;s where I figured a relatively simple rewrite rule should do the trick: in all requests to files ending in .html under \/marginaali\/, replace the 2004 with the o2004.<\/p>\n<p>Well, like I implied in the beginning, this was surprisingly difficult to achieve with my little experience in tweaking .htaccess files. I finally succeeded, however, and here&#8217;s my solution:<\/p>\n<p><code style=\"font-size: 80%\"><a href=\"http:\/\/httpd.apache.org\/docs\/1.3\/mod\/mod_alias.html#redirectmatch\">RedirectMatch<\/a> \/marginaali\/2004\/(.*)\\.html$ http:\/\/mummila.net\/marginaali\/o2004\/$1.html<\/code><\/p>\n<p>I placed this directive after the segment added by WordPress, in the the same .htaccess file that controls the permalinking, in \/marginaali\/. It leaves requests to the WP versions of posts (such as <a href=\"http:\/\/mummila.net\/marginaali\/2004\/11\/28\/sepe\/\">this one<\/a>) intact, while fixing the requests to their html versions with the added &#8216;o&#8217; so that, for example, <a href=\"http:\/\/mummila.net\/marginaali\/2004\/11\/sepe.html\">2004\/11\/sepe.html<\/a> gets redirected to <a href=\"http:\/\/mummila.net\/marginaali\/o2004\/11\/sepe.html\">o2004\/11\/sepe.html<\/a>. (That is an actual example of a page being referred to out on <a href=\"http:\/\/www.uta.fi\/~tlmihap\/celibacy\/133.html\">someone else&#8217;s page<\/a>, which I have no control over.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After poking around with some Rewrite rules and nearly losing my nerve with what seemed to be a choice between a 500 Internal Error and WordPress&#8217; 404 pages, I finally came up with a redirect instruction for my .htaccess file that replaces a subdirectory name in URLs which end in .html. I need this because [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9387,29],"class_list":["post-823","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-blog","tag-hacks-tweaks"],"_links":{"self":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":0,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"wp:attachment":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}