Sharing Space

First a minor clarification. While this serise has been titled a redesign, we're really talking here about first doing a re-implementation in order to enable a re-design.


Once a site is in produciton it's best to do away with .htaccess for performance. This is simple enough as the directives in .htaccess can be put in the Apache configuration file. For these early stages, though, it is great to have a .htaccess file so you can make changes without having to restart. Drupal ships with a .htaccess file that works for re-writing URLs so one can do "clean" URLs.

The problem with the site at hand, however, is it needs to still access the old site while the new Drupal site is going up around it. Drupal's .htaccess file contains the following directives that we are concerned with:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This tells the webserver that if a client requests a file and there is no file by that name and no directory by that name to send /index.php instead and to take the requested "page" and send it as an argument. Thus /node/3 becomes index.php?q=node/3. This works fine if the user requests a regular file. However it breaks down if they request a directory. If a user requests /oldsite/ Apache doesn't know that the "if the file doesn't exist" part applies to /oldsite/index.html until it is too late. Apache merrily serves up index.php.

To solve this problem (and a couple of variations) we add the following three lines before the three above in the .htaccess file:

RewriteRule ^photo(.*)$ [L]
RewriteRule ^staff/specialuser/$   staff/specialuser/index.htm        [L]
RewriteRule ^(.*)/$ $1/index.html [L]

These handle two specific circumstances. If the user requests a path that contains photo, such as the old photo site at they are redirected to the new photo site (separate from Drupal). Along the way specialuser setup their site using index.htm instead of index.html. The second rule solves the case of a user requesting specialuser's website. Finally the last rule says if someone makes a request that ends in a '/' redirect them to the same path but make the request '/index.html' instead. This means that if someone requests a directory like /oldsite/ they get /oldsite/index.html instead of the requesting being turned over to Drupal.

With these changes in place both sites are up and running side by side. Ask for index.php and Drupal will serve the page. Request a file or directory that exists on the webserver and that will be served. Next time we'll look at setting up the Front Page module to start serving the site's main page from Drupal while the magical transformation continues behind the scenes.