{"id":149,"date":"2009-05-27T22:37:50","date_gmt":"2009-05-28T03:37:50","guid":{"rendered":"http:\/\/www.1oc.com\/blog\/?p=149"},"modified":"2009-05-27T22:37:50","modified_gmt":"2009-05-28T03:37:50","slug":"creating-a-static-copy-of-a-dynamic-website","status":"publish","type":"post","link":"http:\/\/blog.1oc.com\/?p=149","title":{"rendered":"Creating a static copy of a dynamic website"},"content":{"rendered":"<p>\u00a0<\/p>\n<p class=\"content\">At work we have several websites that we develop with Plone, but each year we make a new version and we want to keep an archive of the old version.<\/p>\n<p>Since it takes a lot of memory to keep a Zope instance for these old websites that probably won\u2019t need to be edited ever again, it makes sense to make a static copy of the website. It also eliminates the work needed to update the instance when security patches come out (and eliminates security risks, in cases of old versions that are no more maintained).<\/p>\n<p>There are some tools that can help in this case; I chose to use wget, which is available in most Linux distributions by default.<\/p>\n<p>\u00a0<\/p>\n<p><strong>The command line, in short\u2026<\/strong><\/p>\n<p>\u00a0<\/p>\n<pre>wget -k -K  -E -r -l 10 -p -N -F --restrict-file-names=windows -nH <a title=\"http:\/\/website.com\/\" href=\"http:\/\/website.com\/\">http:\/\/website.com\/<\/a><\/pre>\n<pre><strong>\u2026and the options explained\n<\/strong><\/pre>\n<pre>-k : convert links to relative\n-K : keep an original versions of files without the conversions made by wget\n-E : rename html files to .html (if they don\u2019t already have an htm(l) extension)\n-r : recursive\u2026 of course we want to make a recursive copy\n-l 10 : the maximum level of recursion. if you have a really big website you may need to put a higher number, but 10 levels should be enough.\n-p : download all necessary files for each page (css, js, images)\n-N : Turn on time-stamping.\n-F : When input is read from a file, force it to be treated as an HTML file.\n-nH : By default, wget put files in a directory named after the site\u2019s hostname. This will disabled creating of those hostname directories and put everything in the current directory.\n\u2013restrict-file-names=windows : may be useful if you want to copy the files to a Windows PC.<\/pre>\n<pre><\/pre>\n<pre><strong>Possible problems\n<\/strong><\/pre>\n<pre><\/pre>\n<pre>\n\t<li>wget download the homagepage, robots.txt then stops!\nYour robots.txt file probably denies access to your site to search engines. Yes, in recursive mode, wget will respect the robots.txt file, so you will need to remove it before making the copy. Don\u2019t forget to put it back in the static site if that\u2019s what you want.<\/li>\n\t<li>Stylesheets : if you have @import stylesheet imports, wget won\u2019t see them, and won\u2019t download them\u00a0<img decoding=\"async\" class=\"wp-smiley\" src=\"http:\/\/blog.jphoude.qc.ca\/wp-includes\/images\/smilies\/icon_sad.gif\" alt=\":(\" \/>\u00a0You might want to change them to &lt;link rel=\u201dstylesheet\u201d \u2026 \/&gt; imports, which wget will see and download.<\/li>\n\t<li>Stylesheet images : wget won\u2019t download background-images referenced in CSS files. For most websites that should not be too long to download those images manually.<\/li>\n\t<li>Be sure that you CSS files and with \u201c.css\u201d! Apache won\u2019t send the correct mime-type if your file extension is not .css, and Firefox will not use the stylesheet.\n(test.css?color=blue won\u2019t work, change it to test.css?color=blue&amp;ext=.css)\nThe same problem may happen with other files types that need to have a proper mimetype set (video files, for instance)<\/li>\n\t<li><strong>LinguaPlone specific problems<\/strong>\n<ul>\n\t<li>To prevent having several duplicated files with the set_language parameter, you could setup one subdomain for each language, and force the set_language=\u00a0in the Apache redirect rule.<\/li>\n\t<li>I also recommand to change the language link so it points to the main page instead of the current page.<\/li>\n\t<li>You have several possibilities here, but by just doing a wget without changing anything, you may end up with pages where languages are a bit fucked up.<\/li>\n<\/ul>\n<\/li>\n\t<li>&lt;base&gt; tag problem : If you pages contains a base tag (which is true for Plone sites), wget will empty it\u2019s value but leave the base tag there ([base href=\"\" \/]). That works in Firefox, but it will confuse IE, which won\u2019t load any images, CSS or links.To fix it, you can remove the base tag completely with this command :\n<pre>find | grep html$ | xargs perl -i -p -e 's\/&lt;base href=\"\" \/&gt;\/\/g'<\/pre>\n<pre><strong>Downsides\n<\/strong><\/pre>\n<pre><\/pre>\n<pre>\n<ul>\n\t<li>Most file names will change (bad for SEO)<\/li>\n\t<li>May take some manual work to have a working static copy<\/li>\n<\/ul>\nAfter taking care of all the possible problems, you should have a working static site! Be sure to check with both IE and Firefox (at least), because some problems happen in only one browser.\nThen, you can shut down your CMS and server the static content using a standard webserver.\n\nDon\u2019t forget to put a nice 404 page pointing to your main page, since your URLs probably changed, and several visitors will get a 404 error if they come from search engines or bookmarks.\n\n\u00a0\n\n\u00a0<\/pre>\n<\/li>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 At work we have several websites that we develop with Plone, but each year we make a new version and we want to keep an archive of the old version. Since it takes a lot of memory to keep &hellip; <a href=\"http:\/\/blog.1oc.com\/?p=149\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9],"tags":[],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-servers","category-unix"],"_links":{"self":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149"}],"version-history":[{"count":0,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.1oc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}