Redirect only anonymous users to old site
Hi folks,
We're on Drupal 5.1, on a LAMP server. Our old website was/is on a Windows IIS server. We are trying to implement a phased migration. All the content has been migrated into Drupal, but each group needs to check through their content before we redirect their visitors to the new server. The first group is ready to go -- their content has been checked and updated. I know how to put the redirects into IIS to send visitors to their pages over to the Drupal server.
However, once a visitor is at the Drupal server, they can navigate to a bunch of pages that haven't been checked through yet, belonging to the other groups. I need to catch these visits and send them back to the old server.
For now, I've used Redirect directives in the .htaccess file, and that works. But now the groups which haven't migrated yet can't get to their own pages on the Drupal server to make corrections and updates.
How can I distinguish between anonymous users, which should be automatically redirected between the two sites based on migration status, and authenticated users (or users by IP) which should be allowed to access all the pages on Drupal? General approaches I've thought of (but don't know how to implement):
- Put some kind of if statement around the redirect section of .htaccess so that certain IP address visitors don't get redirected away from Drupal
- Unpublish the pages or put them in moderation (we're using Modr8 and revision moderation) so that a visitor trying to access an unpublished or unmoderated page gets redirected to the old site, but an authenticated user can see the moderated page. (Would workflows help to implement this?)
- Put a bunch of PHP in the top of the template.php that checks for role and redirects authenticated users, maybe by taxonomy
- Put a bunch of PHP in template.php but use the module Referer Theme to make a different copy of the theme for people who log in via a special gateway I would provide, maybe something using the Login Destination module
- Somehow tricking a localization method into treating the two servers as different languages and redirecting on the basis of a phony language setting in the authenticated profiles
Any suggestions?

A very short module...
<?php
// $Id$
/**
* A very short redirection module, create your own .info file for it
*/
function redirectme_init() {
global $user;
$url = 'http://www.example.com';
if (!$user && arg(0) != "user") {
header('Location: '. $url);
exit();
}
}
?>
If a user is logged in then their $user variable is set and the code above is ignored. If they're not logged in then they get redirected unless they're trying to log in (if arg(0) is 'user').
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
Super, thanks!
I'll probably modify this a bit to send different taxonomy areas to different pages. (I think I can figure out how to do that.)
Sorry, need more info
I made a directory in modules, put the above into a file called redirect_anon.module, and made a redirect_anon.info file with the basics, and I was able to enable the module in admin. But all the pages are still accessable to anonymous. Do I need to call the redirectme_init function from somewhere, e.g. template.php?
Are there other modules I might have that would interfere with $user being unset, e.g. LoginToboggan?
Thanks!
Hiya!
Hiya!
Nope nothing will cause $user to be unset, if a user is logged in then their entire $user attributes will be set in the $user object no matter what.
I think perhaps you'll need to call the function redirect_anon_init() as redirectme doesn't exist as a module (sorry I'd have pointed this out before, but I assumed it'd be obvious). Be aware with using Drupal API in hook_init as it's called during initialization/ bootstrap so certain commands won't be present for anonymous users.
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
That did it... oops, guess not.
Yes, the name of the function seems obvious in retrospect, but I've never written a module before so I missed it. Unfortunately, though I initially thought this had done the job, it turns out not to have done. But I found out a different way to do what I needed to do-- if a user accesses the site via a different url that puts drupal down a path a ways (which is what I had done by accident), they can access the pages I tried to redirect. Or so it seems, anyway. Since that address is unpublished, I can let the editors use it while everyone else uses the regular address.