Redirection with ModRewrite and GET variables

Yesterday I started working on the redirect in the .htaccess for the homepage. The quick links on the homepage are redirected using ModRewrite then pushed through a php file that logs the action. This lets us monitor their usage so we can make sure the best possible links are available in this drop down. Here’s the code we were using in the .htaccess:

RewriteRule ^r/(.+)$ http://wayne.edu/r.php?url=$1

It was working well with normal URLs but when a URL was passed that had a query string, that query string was being truncated leaving the forwarding php with a URL that didn’t have a query string which then forwarded to the wrong location.After looking deeper into the options available with ModRewrite I found the [QSA] flag. This appends the query string back onto the URL when forwarding, which allowed me to modify the php file that was managing the forwarding so it could reattach the missing query string onto the end of the URL. So now the quick links will forward properly, even with complicated URLs.Here’s that same RewriteRule with the flag:

RewriteRule ^r/(.+)$ http://wayne.edu/r.php?url=$1 [QSA]

The PHP file gained this code which reattaches the query string back onto the end of the URL being passed in.

foreach($_GET as $key => $item){
  if($key != 'url'){
    $pieces[] = $key . ($item != '' ? '=' . $item : '');
  }
}
$url = $_GET['url'];
if(sizeof($pieces) > 0){
  $url .= '?' . implode('&', $pieces);
}

Getting down to business

Over the past two months have been slowing down our client work in an effort to focus on the universities main homepage and central university tools. Being the second day of work things seem to be going as planned, we squashed a few bugs in the homepage and are discussing additional features to the child pages. All of the pages are going to essentially be mini portals, giving the user aggregated information relative to the pages content, kinda like Google Adsense but not for profit.

Cleaning up our sloppiness left over from 2007 is also underway. We are starting out with our file server, it store all the active, archive and tools for projects. Starting out by archiving all the old stuff and updating all the current projects has been tedious but necessary.

In addition our server move is almost complete, just two sites left to go and cwis-1 will be re purposed. Unfortunately they are some high traffic sites, the Public Relations site and the Board of Governors site. Getting those off the old server means we will no longer have to support two versions of our CMS and we can stick to updating just one in a single environment.

New year, New endeavors.

With the new year comes new endeavors. 2008 has started and we are back to work, here is a few things we are bringing with us.

  1. Welcoming Nick West to the team! Nick as worked as a student assistant for about a year and has been hired full time.
  2. A blog dedicated to the daily work of the web communications team at Wayne State University.
  3. The chance to be more open about what we do here and how we do it, taking the web development struggle and making it a resource for all to learn from.