James Crook, web geek ++

Creating a static version of a dynamic site

28 Feb 2011

VIM screenshot

I recently needed to create a static version of a dynamic ColdFusion site.

The client no longer needed access to the legacy ColdFusion CMS running the website but wanted to retain access for the public while moving the site to the server that runs their other (PHP) websites. I didn't make the CF site but the client wanted me to make the static version.

Tricky, but I found a method that works well.

I started by downloading their entire site as rendered html using wget:

wget -r website.com

The resulting files were saved with question marks and ampersands in the filenames, but when put on a server these are interpreted as query strings and as our new server doesn't interpret .cfm files it results in the raw code being loaded. So we can't leave the filenames that way.

'Rename' is a handy utility that works with regex to rename files. I used it here to remove the query-strings and add a .html extension. You could do further renaming to remove spaces and other special characters if you needed to. Basically it works like rename -v 's/search/replace/' [files]

rename -v 's/\.cfm\?(.*)/_cfm_$1\.html/' *.cfm*

Once the filenames are change we need to make make the internal links keep working, without having to edit every file to change where the links point. I chose to do some .htaccess voodoo so that when a page is requested with a .cfm?querystring extension it finds the correct, renamed, file.

In .htaccess, I worked out he following code that loads the new file from a link to the old:

Options +FollowSymlinks RewriteEngine on RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^index\.cfm$ http://website.com/index_cfm_%1.html? [R=301]

The RewriteCond is needed because otherwise .htaccess disregards the query string.

This particular project still needed a bit of manual editing of some site areas where the links were absolute, but I think that the above solution will work in most simple cases.

 

Categories: 

Comments

31 Mar 2013

altefalcope <a href="http://vikawieier.com">xaikalitag</a> Nupestemype http://uillumaror.com - iziananatt Gymnsypeshy http://gusannghor.com Icercefaree

11 Mar 2014

If like me you're trying to learn a brand-new
language thsn anything that makes tthe procedure simpler has obtained to be an excellent point.
I have actually looked at numerous of the defices offered andd have actually uncovered to
mmy price that many of the paid ones are very considerably ineffective.

Add new comment