Follow me on twitter @freeyourpixels
External URL aliasing in Drupal
For clients, I often need to make short URLs that link to long ones, and while services like bit.ly and tinyurl are great, it's even better to have a URL that comes from the client's site. For example, you want www.mysite.com/yoursite to redirect immediately to www.yoursite.com.
There's no terribly easy way to do that in Drupal, and the few modules I've played with are pretty cumbersome and each have their shortcomings. So here's a quick php ditty that will redirect everyone who isn't logged in, and show the actual page for those who are:
<?php
global $user;
if ($user->uid) {
Print "You're logged in.";
}
if (!$user->uid) {
$URL="http://www.yoursite.com";
header ("Location: $URL");
} ?>
It's always nice to add a little Click here if you are not automatically redirected link at the bottom, too, just in case something on the site blows up when you're not looking and leaves users with no way of getting to their destination.