Wow, never thought I'd be able to write this myself but I did it. Please take a look at the code, this is the best I can do. I'm sure it's not optimal, I'm not a PHP coder so feedback is more than welcome.
In the HEAD of your image.php template add this line
`
<link rev="canonical" rel="alternate shortlink shorter" href="http://yourdomain.com/z/<?php echo getImageID(); ?>">
`
In the HEAD of your album.php template add this line
`
<link rev="canonical" rel="alternate shortlink shorter" href="http://yourdomain.com/z/<?php echo getAlbumID(); ?>">
`
Create a folder named 'z' in the root of your domain folder. Add a .htaccess file in it with the following content:
`
RewriteEngine On
RewriteRule ^(.*)/?$ index.php?p=$1 [L,QSA]
`
Add a file called index.php to the folder 'z' with the following code:
`
<?php
$imgId = ($_GET['p']);
$username="your_zenphoto_database_username";
$password="your_zenphoto_database_password";
$database="your_zenphoto_database";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM zp_images WHERE id = ".$imgId;
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
$imgName = $row["filename"];
$albId = $row["albumid"];
}
//Check if it's an image, else assume it's a category
if($imgName==''){
$albId = $imgId;
}
else{
$imgName = $imgName.'/';
}
$query1="SELECT * FROM zp_albums WHERE id = ".$albId;
$result1=mysql_query($query1);
mysql_close();
while($row1 = mysql_fetch_array($result1)) {
$albName = $row1["folder"];
//$albId = $row["albumid"];
}
header("HTTP/1.1 301 Moved Permanently");
header('Location: http://yourdomain.com/zenphoto-directory/'.$albName.'/'.$imgName);
?>
`
In all code above you could replace yourdomain.com with your own shorter URL, if you have one.