The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Making a new site appear within the old

Submitted by nk on Sun, 2011-09-25 03:40

I have created a version 2.0 site and the owner wanted the two to live on, keeping the existing v1 pages read-only because the migration costs couldn't be justified. The new site should appear in the same domain -- no subdomains. Yes, even this can be done with Drupal 7 without hacking core with a little help from Apache.

So, we have an old site called http://www.example.com and we have http://v2.example.com. We will make it so that http://www.example.com homepage shows the http://v2.example.com homepage and then any other page from http://v2.example.com appears under http://www.example.com/v2 for eg.http://www.example.com/v2/user . The solution is to use the proxying feature of Apache -- we could use ProxyPass but using mod_rewrite gives us more control.

Add to the Apache vhost config for www.example.com:

RewriteEngine On
# Homepage
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^/$ http://v2.example.com/ [P,L]
# Don't duplicate the v2 homepage.
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^/v2/?$ http://www.example.com/ [R=301,L]
# Everything else
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^/v2/(.*)$ http://v2.example.com/$1 [P,L]
# Make the old home page available still under v1/home.
# home.example.com is just CNAME and ServerAlias to www.example.com.
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^/v1/home$ http://home.example.com/ [P,L]

For v2.example.com:

RewriteEngine On
# If accessed directly, redirect.
RewriteCond %{HTTP:X-FORWARDED-HOST} ^$
RewriteRule ^/(.+)$ http://www.example.com/v2/$1 [R=301,L]
# If access directly, redirect the homepage.
RewriteCond %{HTTP:X-FORWARDED-HOST} ^$
RewriteRule ^/$ http://www.example.com [R=301,L]

Add to the v2.example.com settings.php:

<?php
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
 
$base_url = 'http://www.example.com/v2';
 
$_SERVER['REQUEST_URI'] = '/v2' . $_SERVER['REQUEST_URI'];
 
$cookie_domain = 'example.com';
 
$conf['reverse_proxy'] = TRUE;
}
?>

Add this to a module:

<?php
function example_url_outbound_alter(&$path, &$options) {
  if (!
$path || $path == '<front>') {
   
$options['external'] = TRUE;
   
$path = $GLOBALS['base_root'];
  }
}
?>

Commenting on this Story is closed.

Submitted by Anonymous on Sun, 2011-09-25 15:32.

In many cases there even no /v2/ folder is necessary. Apache can serve both index.php and *.html pages simultaneously if set up suitably.

If the "old pages" contain a local link e.g. as a "old version menu entry" pointing back to "home" to connect it to e.g. example.com, which is often the case for navigation, the old pages can coexist with a standard Drupal installation. They simply are displayed as static pages as ever, only "new" drupal pages are visible to the drupal processing. I did this twice on D6, and expect no problems with D7 for this.

Obviously that is not the same task as in the post: There are some conditions to the old content, and with some effort it is even possible keep the old startpage in place and stil gain from Drupal functionality for all new content. It stil is a bit more difficult to preserve old folder hierarchies with this method, but it can be done.

I see this as a way to quickly use Drupal and gain time to care later for the old content - either stil keep it static, drop it finally (caring for a info-message, please!), or even use simple URL-aliases to gradually replace old/legacy content one after the other by real drupal pages under the old URL.

Franz

Submitted by Anonymous on Mon, 2011-10-03 08:50.

Where does content lookup validation happen? ie, check whether example.com/v2/content-node-foobar exist then serve, and if doesn't exist proceed to lookup in v1.