Note: If you don’t care about the technical details of switching over a site and its structure, you can probably skip this entry — it may confuse you, or simply bore the heck out of you.
For the old (second) version of this site, I used a lot of ASP scripting to generate dynamic content and automatically change navigation states based on directory paths and query strings. This new (third) version uses PHP and shifts around some of the directory structure. While I can change and control internal links pointing to my own content, lots of external links exist on other sites which point to files on stopdesign. I wanted to make sure as many of those links as possible still pointed to appropriate places on this site.
The largest block of files on this site which changed were part of the Log Archive. The old site used a date-based query string to dynamically pull in appropriate entries through a single master file:
/log/default.asp. Each entry was saved as a fragment of code which waited to get pulled in through ASP’s
Server.Execute method. A six-digit value for the
date key (i.e.
?date="200306") pulled in all entries for that month. An eight-digit value (i.e.
?date="20030624") pulled in any entries for a specific day.
In this new MT-powered version, entries are archived as complete physical files in a date-based hierarchical directory structure. The same values referenced above now live in
/log/2003/06/24/, respectively. Based on what I had seen in various places around the web, I was pretty sure Apache’s mod_rewrite module could help forward all request for all the old filename/query string combinations to the new site’s structure. Since I wasn’t familiar with mod_rewrite, it took a little bit of experimentation to get it to work. But the directives required to forward the query string to the new Log Archive index ended up being very simple. These three lines were placed into the
.htaccess file inside the
RewriteRule ^default\.asp$ index.html [NC,R]
The flags at the end of the last line (in square brackets) ensure the file name match is not case-sensitive (
NC), and that it forces an external redirect (
Since query strings are handled separately, I could pass the untouched query string to the new index file, verify that the
date value consisted either of six or eight digits only through a regular expression, then match the old date IDs to new directory structures and filenames through a simple (but long) manually-created associative array:
// assign months first
$r['200208'] = '/2002/08/';
$r['200209'] = '/2002/09/';
$r['200210'] = '/2002/10/';
// now assign days or ind. entries
$r[‘20020819’] = ‘/2002/08/19/something_new.html’;
$r[‘20020820’] = ‘/2002/08/20/craving_more_style.html’;
$r[‘20020821’] = ‘/2002/08/21/news_worth_noting.html’;
[and on and on…]
The manual creation of the array allowed me to decide if each eight-digit date ID should redirect to a daily or individual entry archive. Once I found the matching string (via a
foreach loop through the array), I needed to append the first portion of the URL (
http://www.stopdesign.com/log) to the string, then redirect any inbound request with a
date value in the query string to the new URL for the appropriate month, day or individual entry archive.
ASP file requests for other sections of the site were handled through simple Apache
Redirect directives. Now that these redirects are working, any external links from other sites pointing to old files on stopdesign are automatically redirected to the correct place in the new structure, preventing the unfortunate 404 File Not Found error page (which I still need to customize).
Ok, if you have a programming background, I know, this is simple stuff. But I’m a designer figuring it out for the first time, and I think it’s pretty cool that it works. And that I’m the one who got it working.