{"id":84,"date":"2007-09-10T14:21:33","date_gmt":"2007-09-10T21:21:33","guid":{"rendered":"http:\/\/historicalwebber.mossiso.com\/archives\/84"},"modified":"2011-03-07T11:05:08","modified_gmt":"2011-03-07T16:05:08","slug":"converting-wordpress-to-static-html","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2007\/09\/10\/converting-wordpress-to-static-html\/","title":{"rendered":"Converting WordPress to static html"},"content":{"rendered":"
UPDATE: Check out the new post on a better way to do this here: Convert WP to Static HTML Part 2<\/a>. Or see the page devoted to the script here: Make WordPress Static<\/a>.<\/p>\n Usually people are wanting to convert their static html pages to some dynamic content management system. I’ve run into the issue of needing to go the other way.<\/p>\n A few professors at GMU love to use WordPress for their classes. It’s a really great way to get more student participation and involve some of those who aren’t so talkative in class.<\/p>\n But these blogs are usually only needed for one semester, and then just sit there. This can be a security risk if they are not kept up to date, and is cumbersome when trying to update many of them (one professor had over 30 blogs!).<\/p>\n Sometimes the content should still be viewable, but the need for a whole cms type back-end no longer exists. Sometimes the professor would just like a copy of the pages for their own future research or whatever.<\/p>\n So, I figured out a way to convert a dynamic WordPress site into static html pages.<\/p>\n Here are the basic steps I used:<\/p>\n UPDATE (2.12.08):<\/strong> Reading a post from Christopher Price<\/a> (who linked to this post) about WP permalinks, I’m thinking using this structure (\/archives\/%post_id%.html) might afford the best results. I often found a page that displayed the raw HTML instead of being rendered. This just might fix that issue.<\/p>\n UPDATE (3.11.08):<\/strong> I did some more dynamic to static conversions today, and found out the best permalink structure to use is just the post name. No extra categories and such. So the best structure to use would be this (\/%postname%.html). The benefit is that the every page is unique with a descriptive name for the url (albeit sometime very long), and there are not as many subdirectory issues that arise.<\/p>\n UPDATE (7.17.09):<\/strong> This time around, I have found that the following seems to work best for permalink: This has the bonus of making the directory for you, thus negating the make directory step. Make sure to use two dashes and not an em dash.<\/li>\n UPDATE (03.11.08):<\/strong> I have found that the old ‘rename<\/strong>‘ command [rename .1 ” *.1<\/strong>]only works on the current directory. If you want to do a recursive renaming you have to use the ‘find<\/strong>‘ command. The above code has changed to reflect this. UPDATE: Check out the new post on a better way to do this here: Convert WP to Static HTML Part 2. Or see the page devoted to the script here: Make WordPress Static. Usually people are wanting to convert their static html pages to some dynamic content management system. I’ve run into the issue of … Continue reading Converting WordPress to static html<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[9,10],"tags":[23,277,278],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-technology","category-wordpress","tag-bash-code","tag-technology","tag-wordpress"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-1m","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":3,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/84\/revisions\/1032"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
\n[code lang=”SQL”]
\nUPDATE `database`.`prefix_options` SET `option_value` = ‘\/%year%\/%monthnum%\/%day%\/%postname%\/’ WHERE `prefix_options`.`option_name` = ‘permalink_structure’ LIMIT 1 ;
\n[\/code] <\/p>\n\/%year%\/%monthnum%\/%day%\/%postname%\/<\/code> And cleaned up the SQL statement.<\/li>\n
\nRewriteEngine On
\nRewriteBase \/path\/to\/wp\/
\nRewriteCond %{REQUEST_FILENAME} !-f
\nRewriteCond %{REQUEST_FILENAME} !-d
\nRewriteRule . \/path\/to\/wp\/index.php [L]
\n<\/code><\/li>\n
\n[code lang=”bash”]wget –mirror –wait=2 -P blogname-static -nH -np -p -k -E –cut-dirs=3 http:\/\/sitename.com\/path\/to\/blog\/[\/code]
\n*** Change –cut-dirs to the appropriate number associated with how many directories are after the domain name. The trailing slash plays a part too. ****
\nUPDATE (03.11.08):<\/strong> I found that the –cut-dirs doesn’t really do anything this time around.
\nUPDATE (7.17.09):<\/strong> This time around, I find the following to work best, even the –cut-dirs. <\/p>\nwget --mirror -P wpsite-static --cut-dirs=3 -nH -p -k -E https:\/\/site.com\/path\/to\/wp\/<\/pre>\n
\n[code lang=”bash”]cp -r \/path\/to\/wp\/wp-content\/* \/path\/to\/static\/wp-content\/[\/code]<\/li>\n
\n[code]rm -f *\/feed [\/code]
\nTo delete all of the now empty direcotries:
\n[code]find . -type d -exec rmdir ‘{}’ \\;[\/code]
\nTo rename the files ###.1 to ###
\n[code]rename .1 ” `find . -type f -name “*.1″`[\/code] That’s two single quotes after the first ‘.1’<\/li>\n
\nUPDATE (7.14.09):<\/strong> When the rename with find doesn\u2019t work, it\u2019s probably because the post has comments, so there is a folder with the same name as the post\u2019s filename. In this case, just move the file (with the .1 extension) into the folder of the same name, but change the name of the file to index.html<\/p>\n
\nUPDATE (03.11.08):<\/strong> I found I needed to backup just a few tables from a database that contained many copies of wordpress. To do this more easily, I used a little script I wrote<\/a> earlier to dump tables with a common prefix. This could also work if you just put in the full name of only the tables you wanted to backup.<\/li>\n